locked
Faqs contii RRS feed

  • Question

  • 8.) What is the value of printf(“%d”); or printf (“%d %d”, 1);?

    Ans – Undefined. Mark it.

    Let’s state the prototype for printf:

    7.19.6.3 The printf function

    Synopsis

    1 #include <stdio.h>
    int printf(const char * restrict format, ...);

    Description
    2 The printf function is equivalent to fprintf with the argument stdout interposed before the arguments to printf.

    Returns
    3 The printf function returns the number of characters transmitted, or a negative value if an output or encoding error occurred.


    Now for the fprintf the standard states:

    The fprintf function writes output to the stream pointed to by stream, under control of the string pointed to by format that specifies how subsequent arguments are converted for output. If there are insufficient arguments for the format, the behavior is undefined. If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored. The fprintf function returns when the end of the format string is encountered.


    9.) What is the use of volatile keyword?

    Ans – Many times compilers make decisions for you to optimize your code. And many a times you don’t mind that. But, there are times when you need to explicitly mention the compiler not to touch the variable while optimization phase. Volatile qualifier does that for you.

    ‘The volatile keyword is a type qualifier used to declare that an object can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread.’

    Get more info here:
    http://en.wikipedia.org/wiki/Volatile_variable


    10.) Can I write a program that prints itself?

    Ans – Programs that print their source code are referred to as Quines. Check this link out:

    http://en.wikipedia.org/wiki/Quine_%28computing%29
    Wednesday, September 26, 2007 1:53 PM

All replies


  • better to post in same thread...
    Thursday, September 27, 2007 10:46 AM