c coding questions and answer

Best questions of preprocessor with answer

(1)
#include<stdio.h>
#define division 10\3
int main(){
    printf("%d",division); 
    return 0;   
}

What will be output if you compile and execute the above code?
(a)3
(b)4
(c)103
(d)Compiler error

(2)
#include<stdio.h>
void display();
void calculate();
#pragma startup calculate
#pragma  exit display
int main(){
    printf("\ncquestionbank");
    return 0; 
}
void calculate(){
    printf("\njava-questionsbank");
}
void display(){
    printf("\njavadoubt");   
}

What will be output if you compile and execute the above code?
(a)cquetionbank
   Java-questionsbank
   javadoubt
(b)java-questionban
   Cquetionbank
   javadoubt
(c) cquetionbank
(d)Compiler error

(3)
#include"stdio.h"
#define sizeof(int) 4
int main(){ 
     int *p=NULL;
     printf("%d" ,p+1);
     return 0; 
}

What will be output if you compile and execute the above code?
(a)2
(b)4
(c)Garbage value
(d)Null pointer error

(4)
#include<stdio.h>
#define int double
#define const struct
#define char sizeof
const student{
    int s;
};
int main(){
    const student s;
    printf("%d" ,char(s));  
    return 0; 
}

What will be output if you compile and execute the above code?
(a)1
(b)8
(c)Run time error
(d)Compiler error

(5)
#include<stdio.h>
#define cube(x) (x*x*x)
int main(){
    int x=2,y,z;
    y=cube(++x);
    z=++y+386/cube(++x);
    printf("%d %d %d",++x,y,z);
    return 0; 
}

What will be output if you compile and execute the above code?
(a)9 126 126
(b)4 27  126
(c)4 27  92
(d)Compiler error

(6)
#include<stdio.h>
#define find(a,b) a##b
int main(){
    int a=10;
    int b=20;
    int ab=15;
    printf("%d",find(a,b)-ab);
    return 0; 
}

What will be output if you compile and execute the above code?
(a)0
(b)5
(c)1005
(d)Compiler error

(7)
#include<stdio.h>
#define max 0\5
int main(){
    #if max
         printf("cquestionbnk");
    #elif max+1
         printf("java-questionsbank");
    #else
         printf("blogspot.com");
    #endif
    return 0; 
}

What will be output if you compile and execute the above code?
(a)cquestionbank
(b)java-questionsbank
(c)blogspot.com
(d)Compiler error

(8)
#include<stdio.h>
#define option1 a++;\
printf("%d",a);
#define option2 printf("%d",a);
int main(){
    int a=10;
    if(a++)
           {option1}
    else
         option2  
    return 0; 
}

What will be output if you compile and execute the above code?
(a)10
(b)11
(c)12
(d)Compiler error

Answer of preprocessor questions:
1. (c)
2. (b)
3. (a)
4. (b)
5. (a)
6. (a)
7. (a)
8. (c)
Post a Comment