Day#52 'C' Coding Challenge

Day#52 'C' Coding Challenge

What is the output of the below code?

#include <stdio.h> char * func_ptr; char * func(void); void main() { char *func_ptr; char *func(); func_ptr = func(); printf("%s",func_ptr); } char * func(void) { char name[30] = "TalentEve.com"; return name; }

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

The above code has a function whose char * func(void); return  type is character pointer.
A character pointer char *func_ptr has been declared.
This statement func_ptr = func(); is calling the function func().
func() has an array name with size 30 (string) and initialized to TalentEve.com
name points to the starting address of the array and address is returned when we return name.
printf("%s",func_ptr); prints the actual value of the string stored 
printf("%d",func_ptr); prints the address

Post a Comment

0 Comments