This is a mock Exam for the C programmers. It is created by Genesis InSoft Limited
(admin@genesisinsoft.com)
and may be freely distributed so long as it is unmodified. Please email us if you
have any corrections or comments.
What is the output of the program?
#include <stdio.h>
// Assume size of integer as 4 bytes
void main()
{
char (*p)[3];
printf("\n %d %d", sizeof(*p),
sizeof(p));
}
- 12 4
- 3 4
- 1 3
- 4 12
Answer to Question 1
What is the output of the program?
#include <stdio.h>
void main()
{
const char* ptr = "Genesis";
printf(" %c ", (*++ptr)++);
}
- No error, output is e
- No error, output is n
- No error, output is G
- l-value specifies const object
Answer to Question 2
The functionality of "ferror(FILE *)" is
- ferror is a macro that tests the given stream for a read error only
- ferror is a macro that tests the given stream for a file open error
- ferror is a macro that tests the given stream for a read or write error
- ferror is a macro that tests the given stream for a file close error
Answer to Question 3
Which of the following function does not return an integer value?
- printf
- scanf
- strcpy
- strlen
Answer to Question 4
What is the output of the program?
#include <stdio.h>
main()
{
static char Arr[8] = "Genesis";
char* ptr = &Arr[6] - 3;
printf("\n %s", ptr);
}
- e
- sis
- esis
- n
Answer to Question 5
Which of the following functions support dynamic memory allocation?
- malloc
- realloc
- calloc
- All the three A, B and C
Answer to Question 6
What is the significance of putw() function?
- writes only character data to the file in text mode
- writes only integer data to the file in binary mode
- writes integer data to the file in text mode
- writes character data to the file in binary mode
Answer to Question 7
What is the output of the program?
#include <stdio.h>
main()
{
for( ; ; )
main();
}
- Error: syntax error at or before;
- Executes once
- It will result in infinite loop until stack overflow occurs
- Error: illegal call to function main()
Answer to Question 8
What is the output of the program?
#include <stdio.h>
// Assume integer is 4 bytes
struct {
char *p;
int (*fun)();
} a;
void main()
{
printf("\n %d %d %d ", sizeof(a),
sizeof(a.p), sizeof(a.fun));
}
- 8 4 4
- 5 1 4
- 6 2 4
- Error: pointer to functions is not allowed in structures
Answer to Question 9
What is the output of the program?
#include <stdio.h>
void main()
{
int Var = 90;
if(Var += Var == ++Var == 89)
printf("
%d ",Var);
}
- 180
- 91
- 90
- 182
Answer to Question 10
Which of the functions always write the output to Video Display Unit?
- puts
- putc
- putch
- fputs
Answer to Question 11
Which of the declarations cannot be performed above main()?
- variables of auto storage class
- enum declaration
- variables of extern storage class
- static union declaration
Answer to Question 12
What is the output of the program if the input is 103?
main()
{
int p = 234;
printf(" %d ", printf("%d",
p), scanf("%d", &p));
}
- 3 103
- 103
- 103 3
- 103 2
Answer to Question 13
What is the difference between scanf() and gets() while scanning a bunch of characters??
- scanf() takes input from stdin, but gets() gets input from console
- scanf() put a null at the end of the string, but gets() does not
- gets() can scan even the spaces, but scanf() cannot
- None of the above
Answer to Question 14
Which of the functions compares two strings ignoring the case?
- strcmp
- strncmp
- stricmp
- strcpy
Answer to Question 15
What is the output of the program?
int fun(int num)
{
return printf(" %d ", num);
}
void main()
{
printf(" Genesis ", fun(123),
" & Genesis");
}
- 123 Genesis
- Genesis 123
- 3 Genesis
- None of the above
Answer to Question 16
What is the output of the program?
void print(char *s)
{
if(*s)
print(++s);
printf("%c", *s);
}
main()
{
char str[] = "Genesis";
print(str);
}
- genesis
- sisene
- siseneg
- None of the above
Answer to Question 17
Where will the output of the program be printed?
main()
{
fprintf(stdprn, "Genesis InSoft
Limited") ;
}
- Standard output device
- Standard error output device
- Standard auxiliary device
- Standard printer
Answer to Question 18
What is the output of the program?
const int MAX = 15;
void main()
{
enum e{a, b, MAX};
printf("%d %d %d", a, b, MAX);
}
- 0 1 2
- 1 2 3
- 1 2 15
- 0 1 15
Answer to Question 19
What is the purpose of the fcloseall() function?
- closes all the streams including standard streams
- closes all the streams other than standard streams
- closes all the input streams
- closes all the output streams
Answer to Question 20
Answers
Answer 1 - B
Back to question 1
Answer 2 - D
Back to question 2
Answer 3 - C
Back to question 3
Answer 4 - C
Back to question 4
Answer 5 - C
Back to question 5
Answer 6 - D
Back to question 6
Answer 7 - B
Back to question 7
Answer 8 - C
Back to question 8
Answer 9 - A
Back to question 9
Answer 10 - B
Back to question 10
Answer 11 - C
Back to question 11
Answer 12 - A
Back to question 12
Answer 13 - C
Back to question 13
Answer 14 - D
Back to question 14
Answer 15 - C
Back to question 15
Answer 16 - A
Back to question 16
Answer 17 - B
Back to question 17
Answer 18 - D
Back to question 18
Answer 19 - A
Back to question 19
Answer 20 - B
Back to question 20