My Report

C Preprocessor Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C code?

#include<stdio.h>
#define max 20
main()
{
    #ifndef max
    #define min 10
    #else
    #define min 30
    #endif
    printf("%d",min);
}

2. Which of the following is not a preprocessor directive?

3. What will be the output of the following C code?

#include<stdio.h>
#define hello 10
main()
{
    #ifdef hello
    #undef hello
    #define hello 100
    #else
    #define hello 200
    #endif
    printf("%d",hello);
}

4. The purpose of the preprocessor directive #error is that ____________

5. What will be the output of the following C code?

#define sqr(x) x*x
main()
{
    int a1;
    a1=25/sqr(5);
    printf("%d",a1);
}

6. What will be the output of the following C code?

#include<stdio.h>
#define hello 
main()
{
    #ifdef hello
    #define hi 4
    #else
    #define hi 5
    #endif
    printf("%d",hi);

}

7. What will be the output of the following C code?

#include<stdio.h>
#define INDIA 1
#define US 2
#define CC US
main()
{
    #if CC==INDIA
    printf("Rupee");
    #elif CC==US
    printf("Dollar");
    #else
    printf("Euro");
    #endif 
}

8. What will be the output of the following C code?

#include<stdio.h>
#define sf 10
main()
{
    if(sf==100)
        printf("good");
    else
    {
        printf("bad");
        sf=100;
    }
    printf("%d",sf);
}

9. What will be the output of the following C code?

#include<stdio.h>
void f()
{
    #define sf 100
    printf("%d",sf);
}
int main()
{
    #define sf 99;
    f();
    printf("%d",sf);
}

10. What will be the output of the following C code?

#include<stdio.h>
#define san 10
main()
{
    #ifdef san
    #define san 20
    #endif
    printf("%d",san);
}

 

Start practicing “1000 MCQs on C”, and once you are ready, you can take tests on all topics by attempting our “C Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.