Examveda
Examveda

What will be output after executing following code?
#include<stdio.h>
# define a 10
void main()
{
    printf("%d..", a);
    foo();
    printf("%d", a);
}
void foo()
{
   #undef a
   #define a 50
}

A. 10..50

B. 10..10

C. 0

D. Error

Answer: Option B


This Question Belongs to C Program >> C Preprocessor

Join The Discussion

Comments ( 4 )

  1. Dikonda Sursan
    Dikonda Sursan :
    6 years ago

    what is the functionality of #undef...
    lets discuss
    it should be 10..50, why it is 10..10

  2. Umang Mahant
    Umang Mahant :
    7 years ago

    Tej Deep coorect!
    just like the previous sum

  3. Srikanya Katikala
    Srikanya Katikala :
    7 years ago

    correct option is B
    since the macro which is defined, is applicable for all the functions mentioned below. so up to the function invocation the macro a = 10
    And in the function body, macro a becomes undefined. and again redefined in the function body as a = 50. whatever the changes we have made in the function body is only accessible in the the function. and these modification not applicable outside of that particular function. so macro a is not undefined.

  4. Tej Deep
    Tej Deep :
    7 years ago

    Actually it should give error, no proper header file..So the correct answer must be D

Related Questions on C Preprocessor