Output of c program

What would be the output of follow c program?

 

#include<stdio.h>
char *getString()
{
char str[] = “Will I be printed?”;
return str;
}
int main()
{
printf(“%s”, getString());
getchar();
}

Asked on January 26, 2020 in program.

Output: Some garbage value

The above program doesn’t work because array variables are stored in Stack Section. So, when getString returns values at str are deleted and str becomes dangling pointer.

on January 26, 2020.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.