What is the output of the below code?
#include <stdio.h> char *string = "Embeddeddesignblog"; void str_manip(char* string) { string++; } void main() { char *arr_str = (void *)malloc(20*sizeof(char)); strcpy(arr_str, "TalentEve"); str_manip(&arr_str); printf("%s",arr_str); free(arr_str); }
--------------------------------------------------------------
The above code declared a character pointer string which is accessible through out the file. pointer arr_str has been allocated memory using malloc function.
TalentEve has been copied to arr_str using string copy function.
The address of arr_str has been passed as variable when the function str_manip() is called.
In the str_manip() function, address value has been incremented but neither it is returned nor it affects the other operations as this is local to the fucntion.
So, in the printf() function, when arr_str has been printed, TalentEve gets printed.
0 Comments