Tuesday, August 5, 2014

C Programming

1. 
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?
#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
    int x=10, y=20;
    SWAP(x, y, int);
    printf("%d %d\n", x, y);
    return 0;
}
A.It compiles
B.Compiles with an warning
C.Not compile
D.Compiles and print nothing

2. 
In which stage the following code
#include<stdio.h>
gets replaced by the contents of the file stdio.h
A.During editingB.During linking
C.During executionD.During preprocessing
3. 
What will be the output of the program?
#include<stdio.h>
#define MAN(x, y) ((x)>(y)) ? (x):(y);

int main()
{
    int i=10, j=5, k=0;
    k = MAN(++i, j++);
    printf("%d, %d, %d\n", i, j, k);
    return 0;
}
A.12, 6, 12B.11, 5, 11
C.11, 5, GarbageD.12, 6, Garbage
4. 
What will be the output of the program?
#include<stdio.h>
#define SQUARE(x) x*x

int main()
{
    float s=10, u=30, t=2, a;
    a = 2*(s-u*t)/SQUARE(t);
    printf("Result = %f", a);
    return 0;
}
A.Result = -100.000000B.Result = -25.000000
C.Result = 0.000000D.Result = 100.000000
5. 
What will be the output of the program?
#include<stdio.h>
#define SQR(x)(x*x)

int main()
{
    int a, b=3;
    a = SQR(b+2);
    printf("%d\n", a);
    return 0;
}
A.25B.11
C.ErrorD.Garbage value

No comments: