Monday, August 4, 2014

C Programming

1. 
What will be the output of the program?
#include<stdio.h>
int main()
{
    int x=55;
    printf("%d, %d, %d\n", x<=55, x=40, x>=10);
    return 0;
}
A.1, 40, 1B.1, 55, 1
C.1, 55, 0D.1, 1, 1

2. 
What will be the output of the program?
#include<stdio.h>
int main()
{
    int i=2;
    printf("%d, %d\n", ++i, ++i);
    return 0;
}
A.3, 4
B.4, 3
C.4, 4
D.Output may vary from compiler to compiler
3. 
What will be the output of the program?
#include<stdio.h>
int main()
{
    int k, num=30;
    k = (num>5 ? (num <=10 ? 100 : 200): 500);
    printf("%d\n", num);
    return 0;
}
A.200B.30
C.100D.500
4. 
What will be the output of the program?
#include<stdio.h>
int main()
{
    char ch;
    ch = 'A';
    printf("The letter is");
    printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);
    printf("Now the letter is");
    printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');
    return 0;
}
A.The letter is a
Now the letter is A
B.The letter is A
Now the letter is a
C.ErrorD.None of above
5. 
What will be the output of the program?
#include<stdio.h>
int main()
{
    int i=2;
    int j = i + (1, 2, 3, 4, 5);
    printf("%d\n", j);
    return 0;
}
A.4B.7
C.6D.5

No comments: