What will be the output of the following C code? [code]#include<stdio.h> void f() { #define sf 100 printf("%d",sf); } int main() {

Sơn Lê

Member
What will be the output of the following C code?
Code:
#include<stdio.h>
void f()
{
    #define sf 100
    printf("%d",sf);
}
int main()
{
    #define sf 99;
    f();
    printf("%d",sf);
}
A. error
B. 100
C. 99
D. 10099
 
Answer: a
Explanation: Macro definition is global even if it is appears within the function scope. In this case the macro sf is defined in the function f(). Hence it results in a compile time error.
 

Tìm kiếm

Back
Top