My Report

C Preprocessor Test – 3


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. Which of the following operators is used to concatenate two strings without space?

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

#include <stdio.h>
#define display( n ) printf( "a" #n " = %d", a##n )
int main()
{
   display(3);
}

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

#include <stdio.h>
#define p( n ) printf( "t" #n " = %d", t##n )
int t3=10;
int main()
{
   p(3);
}

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

#include <stdio.h>
#define p( n,m ) printf( "%d", m##n )
int main()
{
   p(3,4);
}

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

#include <stdio.h>
#define hello( n ) a##n
int a3;
int main()
{
    int x;
    x=hello(3);
    if(x!=0)
        printf("hi");
    else
        printf("good");
}

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

#include 
#define p( n ) printf( "t%%\n" #n " = %d", t##n )
int t3=10;
int main()
{
    int x;
    x=p(3);
}

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

#include <stdio.h>
#define p( n ) printf( "t*" #n " = %s", t##n )
char tsan[]="tsan";
int main()
{
    int x;
    x=p(san);
}

8. The following C code results in an error.

#include <stdio.h>
#define world( n ) printf( "t^^" #n" = %c", t##n )
int t3=1;
int main()
{
   world(3);
}

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

#include 
#define p( n,m ) printf( "%d", m##n )
#define q(a,b) printf("%d",a##b)
main()
{
   p(3,4);
   q(5,6);
}

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

#include <stdio.h>
#define hello( n ) printf( "a" #n "= %d", a##n )
int a3=3;
int main()
{
    #ifdef a3
       hello(3);
   #else
       printf("sorry");
   #endif
}

 

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.