1

the following code:

#include<stdio.h>
void main()
{

    int i=100,j=200;
    printf("%d.....%d");


 }

gives 200.....100 as the output. Could someone explain how printf works without datalist

  • 1
    possible duplicate of [Behaviour of printf when printing a %d without supplying variable name](http://stackoverflow.com/questions/437816/behaviour-of-printf-when-printing-a-d-without-supplying-variable-name) – Jayanga Kaushalya Aug 05 '15 at 13:54

2 Answers2

1

It provides a warning at compile time (warning: too few arguments for format), and is not documented, therefore it's undefined behaviour and should not be used. Different compilers are likely to have different behaviours and behaviour may even change between versions of the same compiler.

Try reading about it on Wikipedia for more info.

Robadob
  • 5,319
  • 2
  • 23
  • 32
0

It is some garbage value in the stack since you haven't provided any integer arguments. printf() function doesn't know there are no arguments present and it will search the related stack location and print what ever there is. And as mentioned in Robadob's answer, behavior will change according to the compiler.

Jayanga Kaushalya
  • 2,674
  • 5
  • 38
  • 58