1.
#include <stdio.h>
int main()
{
char ch = 'A';
printf("%d\n", ch);
return 0;
}
- A
- 'A'
- 65
- 97
Ans- 3
2.
Which of the following is not a valid declaration in C ?
1.short int x;
2.signed short x;
3.short x;
4.unsigned short x;
- 3 and 4
- 1
- 2
- All are valid
Ans- 4
3.
#include <stdio.h>
int i;
int main()
{
if (i)
;
else
printf("Ëlse");
return 0;
}
- if block is executed.
- else block is executed
- It is unpredictable as i is not initialized.
- Error: misplaced else
Ans- 2
4.
void swap(int x, int y)
{
int tmp;
tmp = x;
x = y;
y = tmp;
}
- Call swap (a, b)
- Call swap (&a, &b)
- swap(a, b) cannot be used as it does not return any value
- swap(a, b) cannot be used as the parameters passed by value
Ans- 4
5.
What will be the output of the following code snippet?
#include <stdio.h>
int foo(int* a, int* b)
{
int sum = *a + *b;
*b = *a;
return *a = sum - *b;
}
int main()
{
int i = 0, j = 1, k = 2, l;
l = i++ || foo(&j, &k);
printf("%d %d %d %d", i, j, k, l);
return 0;
}
- 1 2 1 1
- 1 1 2 1
- 1 2 2 1
- 1 2 2 2
Ans- 1
No comments:
Post a Comment