Printf function parameters

#include <stdio.h>

int main()
{
    printf(5 + "abhishekdas\n") ;
    return 0 ;
}

The conclusion of the program hekdas. How it works? Should it show an error? How can I write something like 5 + "abhishekdas"inside a function printf?

+4
source share
2 answers
5+"abhishekdas\n"  ==> "abhishekdas\n"+5 ==> &"abhishekdas\n"[5] ==> "hekdas\n"
+9
source

5+"abhishekdas"

equivalently &"abhishekdas"[5], which is the address of the sixth element of the array.

"abhishekdas"- string literal: its type is the type of the array. Like every array object, when it is evaluated in an expression, it is converted to a pointer type. So, 5+"abhishekdas"a simple pointer arithmetic.

+4
source

All Articles