Home » C Programming » Strings

What will be the output of the program? #include int main() { char str[25] = "CuriousTab"; printf("%s\n", &str+2); return 0; }

Correct Answer: Garbage value

Explanation:

Step 1: char str[25] = "CuriousTab"; The variable str is declared as an array of characteres and initialized with a string "CuriousTab".


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 "CuriousTab". Therefore &str+2 is another memory location.


Hence it prints the Garbage value.


← Previous Question Next Question→

More Questions from Strings

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion