Discussion :: Strings
-
What will be the output of the program ?
#include
int main() { char str[25] = "FresherGate"; printf("%s\n", &str+2); return 0; }
Answer : Option A
Explanation :
Step 1: char str[25] = "FresherGATE"; The variable str is declared as an array of characteres and initialized with a string "FresherGATE".
Step 2: printf("%s\n", &str+2);
=> In the printf statement %s is string format specifier tells the compiler to print the string in the memory of &str+2
=> &str is a location of string "FresherGATE". Therefore &str+2 is another memory location.
Hence it prints the Garbage value.
Be The First To Comment