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.
'C' is a
- machine language
- low level language
- middle level language
- high level language
Answer to Question 1
What is the error in the program?
char count;
main()
{
int count = 70;
{
extern int count;
printf("\n
%d ", count);
}
}
- Error: Type mismatch in redeclaration of ' nn'
- Error: Multiple declaration for 'nn'
- Error: Storage class 'extern' is not allowed here
- Linker Error: Undefined symbol 'nn'
Answer to Question 2
What is the output of the program?
void main()
{
int val = (5, val = 5)/++val;
printf("\n %d ", val);
}
- 5
- 1
- 6
- 0
Answer to Question 3
Which of the following statements is used to return more than one value from a function?
- return 1,2,3 ;
- return (1,2,3) ;
- return ((1), (2), (3));
- None of the above
Answer to Question 4
Which of the following is wrong with respect to structures?
- Having the same name for a structure and its variable
- It has functions as its data members
- It has a data member, which is of the same structure kind
- Both B and C
Answer to Question 5
What is the error in the code shown below?
union
{
int val1 : 5;
char val2;
};
- Declaration of variables is not possible due to the absence of tag name
- Arrays of this union cannot be created
- Cannot be used in file handling
- All the three B, C and D
Answer to Question 6
What is an '&' operator?
- logical
- unary
- bitwise
- ternary
Answer to Question 7
What is the difference between malloc and calloc?
- in allocation of memory
- in return types
- number of arguments
- None of the above
Answer to Question 8
What is the default promotion for 'float' in va_arg?
- double
- int
- long int
- char
Answer to Question 9
What is the error in the program?
main()
{
int a = 12;
int *ptr = &a;
printf( " %d %d ", *ptr /*ptr,
*ptr**ptr);
}
-
No error, output is 1 144
-
No error, output is 144 144
-
Unexpected end of file found
-
Error: illegal pointer operation
Answer to Question 10
What is the significance of the function realloc()?
- realloc() adjusts the size of the allocated block to specified size
- realloc() allocates memory on far heap
- It is used to allocate more than 64k bytes
- realloc() allocates the specified number of bytes in registers
Answer to Question 11
What is the error in the program?
main()
{
typedef struct personal
{
int name[25]:15;
}
personal; personal person;
}
- Error: Bit fields must be signed or unsigned int
- Error: Multiple declaration for 'personal'
- Error: Undefined symbol 'personal'
- Error: Size of the type is unknown or zero
Answer to Question 12
What is the return type of fflush()?
- void
- FILE*
- char*
- int
Answer to Question 13
What is the error in the program?
void myprintf()
{
printf("\n %d ", printf("Genesis"));
}
main() {
printf("\n %d ", myprintf());
}
- Error: Type mismatch in 'printf'
- The return type of a function must be an integer
- Error: printf cannot return anything
- Cannot convert from 'void' to '...'
Answer to Question 14
What is the meaning of a static function?
- It is local to a file in which it is declared
- It is local to main()
- The set of variables used in the function is 'static'
- All the linked files can access it
Answer to Question 15
What is the output of the program?
# include <stdio.h>
void main()
{
int main = 90;
top : printf("Label1");
if(main)
goto top;
}
- Infinite
- Label1
- No output
- label top is invalid
Answer to Question 16
How many times is the 'for' loop/statement is executed in the following code.
main()
{
unsigned char ch;
for(ch = 0; ch <= 255; ch++);
}
- Infinite
- 255
- 256
- 127
Answer to Question 17
What is maximum number of 'case' values in a switch statement?
- 255
- 127
- No specific limit
- 128
Answer to Question 18
What is the output of the program?
void main()
{
int x = (90, x = 90)+++x;
printf("\n %d ", x);
}
- 90
- 1
- 181
- 91
Answer to Question 19
Where do we use a 'continue' statement?
- In 'if' statement
- In 'switch' statement
- In 'goto' labels
- None of the above
Answer to Question 20
Answers
Answer 1 - C
Back to question 1
Answer 2 - A
Back to question 2
Answer 3 - B
Back to question 3
Answer 4 - D
Back to question 4
Answer 5 - D
Back to question 5
Answer 6 - D
Back to question 6
Answer 7 - C
Back to question 7
Answer 8 - C
Back to question 8
Answer 9 - A
Back to question 9
Answer 10 - C
Back to question 10
Answer 11 - A
Back to question 11
Answer 12 - A
Back to question 12
Answer 13 - D
Back to question 13
Answer 14 - D
Back to question 14
Answer 15 - A
Back to question 15
Answer 16 - A
Back to question 16
Answer 17 - A
Back to question 17
Answer 18 - C
Back to question 18
Answer 19 - C
Back to question 19
Answer 20 - D
Back to question 20