Day#28 'C' Coding Challenge

Day#28 'C' Coding Challenge

What is the output of the below code?

#include<stdio.h> void main() { char *arr1 = "TalentEve"; char arr2[] = "Embeddeddesignblog"; arr1 = "embeddeddesignblog"; arr2 = "TalentEve"; printf("%s\n%s\n",arr1,arr2); }

-----------------------------------------------------------------------

The above code tests below scenarios:

1. Assignment to array type
2. Assignment to pointer

-----------------------------------------------------------------------

arr1 is a pointer and is assigned a value "TalentEve"
arr2 is an array and is assigned "Embeddeddesignblog"
When arr1 is assigned "embeddeddesigblog", this is completely acceptable as arr1 holds the value
arr2 is an array name and points to the starting location of the array, this cannot be assigned value directly.

Post a Comment

0 Comments