Unit II
Assignment II
Q1:- What will be the output of the program code?
#include<stdio.h>
#define a 10
void main()
{
#define a 50
printf("%d", a);
}
a. 50
b. 10
c. Compiler Error
d. None of These
Q2:- What is the output of following program?
#include <stdio.h>
#define macro(n, a, i, m) m##a##i##n
#define MAIN macro(n, a, i, m)
int MAIN()
{
printf("hello");
return 0;
}
a) Compiler Error
b) hello
c) MAIN
d) Main
Q3:- What is the output of following program?
# include <stdio.h>
# define scanf "%s hello world "
int main()
{
printf(scanf, scanf);
return 0;
}
a) Compiler Error
b) %s hello world
c) hello world
d) %s hello world hello world
Q4:- What is the output of following program?
#include <stdio.h>
#define a 10
int main()
{
printf("%d ",a);
#define a 50
printf("%d ",a);
return 0;
}
a) Compiler Error
b) 10 50
c) 50 50
d) 10 10
Q5:- Which file is generated after pre-processing of a C program?
a) .p
b) .i
c) .o
d) .m
6. Predict the output of following C program
#include <stdio.h>
int main()
{
char a = '\01';
printf("%3d", a);
return 0;
}
a.3d
b._ _ _1
c.8
d.10
7. WAP to find the area of circle using #define preprocessor
#include <stdio.h>
#define PI 3.1415
#define circleArea(r) (PI*r*r)
int main()
{
int radius;
float area;
printf("Enter the radius: ");
scanf("%d", &radius);
area = circleArea(radius);
printf("Area = %.2f", area);
return 0;
}
8. Example of any predefined Macro:
predefined Macros
C Program to find the current time
#include <stdio.h>
int main()
{
printf("Current time: %s",__TIME__); //calculate the current time
}
10. More example of macro
A predefined macro __FILE__ contains the location of a C programming file, it is working
on. For example:
#include <stdio.h>
int main(){
printf("%s",__FILE__);
}
11. To print out a and b given below, which of the following printf() statement will you
use?
#include<stdio.h>
float a=3.14;
double b=3.14;
A. printf("%f %lf", a, b);
B. printf("%Lf %f", a, b);
C. printf("%Lf %Lf", a, b);
D. printf("%f %Lf", a, b);
14. What will be the output of the program ?
#include<stdio.h>
int main()
float a=3.15529;
printf("%2.1f\n", a);
return 0;
A. 3.00
B. 3.15
C. 3.2
D. 3
15. What will be the output of the program ?
#include<stdio.h>
int main()
printf("%%%%\n");
return 0;
A. %%%%%
B. %%
C. No output
D. Error
16. What will be the output of the program ?
#include<stdio.h>
int main()
printf("%c\n", ~('C'*-1));
return 0;
A. A
B. B
C. C
D. D