#include<stdio.h> void main() { printf(5+"good morning");/*need explanation for this line return 0; } The output of the program is - morning can anyone explain how?
Prototype of printf
int printf(const char *format, ...); Here format is a type of const char* and point to address of first element of string literal. When you pass 5+"Good morning" in printf, what you are really passing is the memory address of the string plus 5. The plus 5 means printing will start 5 chars beyond the start of the string, and the space after the word "Good",counts as a char.
when you call with 5+"good morning" parameter is converted to pointer. That means there is string constant "good morning" stored somewhere in the executable and compiler pass its pointer. something like this:
const char txt[]="good morning\0"; printf(5+txt); So the printf will obtain the evaluated pointer txt+5 which bypassed first 5 characters in the string (as one char is single BYTE and single memory address on 8bit WORD addressing machines).
printf((char*restrict const const const const)??<&5??("good morning":>%>);.