C Programming Multiple Choice Question - Functions And Pointers
This section focuses on the "Functions And Pointers" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. The keyword used to transfer control from a function back to the calling function is
A. switch
B. goto
C. return
D. exit
View Answer
Ans : C
Explanation: The keyword return is used to transfer control from a function back to the calling function.
2. What is the default return type if it is not specified in function definition?
A. void
B. int
C. float
D. short int
View Answer
Ans : B
Explanation: None
3. The default parameter passing mechanism is
A. Call by value
B. call by reference
C. call by value result
D. None
View Answer
Ans : A
Explanation: None.
4. Pick the correct statements.
I. The body of a function should have only one return statement
II. The body of a function may have many return statements.
III. function can return only one value to the calling environment.
IV. If return statement is omitted, then the function does its job but returns no value to the calling environment.
A. I and II
B. I and III
C. II and III
D. II anf IV
View Answer
Ans : C
Explanation: None
5. Functions can return structure in c?
A. TRUE
B. FALSE
C. May Be
D. Can't Say
View Answer
Ans : A
Explanation: Yes, functions can return structure
6. Forward declaration is absolutely necessary
A. If a function returns a non-integer quantity
B. If the function call precedes its definition
C. If the function call precedes its definition and the function returns a non integer quantity
D. None of the above
View Answer
Ans : C
Explanation: If the function call precedes its definition and the function returns a non integer quantity
7. In C, what is the meaning of following function prototype with empty parameter list
void fun()
{
/* .... */
}
A. Function can only be called without any parameter
B. Function can be called with any number of parameters of any types
C. Function can be called with any number of integer parameters.
D. Function can be called with one integer parameter.
View Answer
Ans : B
Explanation: Empty list in C mean that the parameter list is not specified and function can be called with any parameters. In C, to declare a function that can only be called without any parameter, we should use "void fun(void)" As a side note, in C++, empty list means function can only be called without any parameter. In C++, both void fun() and void fun(void) are same.
8. A pointer is
A. A variable that stores address of an instruction
B. A variable that stores address of other variable
C. A keyword used to create variables
D. None of these
View Answer
Ans : B
Explanation: a pointer is a programming language object that stores the memory address of another value located in computer memory. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer.
9. The reason for using pointers in a Cprogram is
A. Pointers allow different functions to share and modify their local variables.
B. To pass large structures so that complete copy of the structure can be avoided.
C. Pointers enable complex “linked" data structures like linked lists and binary trees.
D. All of the above
View Answer
Ans : D
Explanation: (A) With pointers, address of variables can be passed different functions can use this address to access the variables. (B) When large structure variables passed or returned, they are copied as everything is passed and returned by value in C. This can be costly with structure containing large data. To avoid this copying of large variables, we generally use poitner for large structures so that only address is copied. (C) With pointers, we can implement "linked" data structures. Java uses reference variables to implement these data structures. Note that C doesn't support reference variables.
10. How can you write a[i][j][k][l] in equivalent pointer expression?
A. (((***(a+i)+j)+k)+l)
B. ((**(*(a+i)+j)+k)+l)
C. (*(*(*(a+i)+j)+k)+l)
D. *(*(*(*(a+i)+j)+k)+l)
View Answer
Ans : D
Explanation: *(*(*(*(a+i)+j)+k)+l)
Also check :
Discussion