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


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


3. The default parameter passing mechanism is

A. Call by value
B. call by reference
C. call by value result
D. None

View Answer


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


5. Functions can return structure in c?

A. TRUE
B. FALSE
C. May Be
D. Can't Say

View Answer


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


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


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


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


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


11. What is wild pointer?

A. Pointer which is wild in nature
B. Pointer which has no value.
C. Pointer which is not initialized
D. None

View Answer


12. Address stored in the pointer variable is of type __________.

A. Integer
B. Float
C. Array
D. Character

View Answer


13. In order to fetch the address of the variable we write preceding _________ sign before variable name.

A. Percent(%)
B. Comma(,)
C. Ampersand(&)
D. Asteric(*)

View Answer


14. Comment on this const int *ptr;

A. You cannot change the value pointed by ptr
B. You cannot change the pointer ptr itself
C. Both (a) and (b)
D. You can change the pointer as well as the value pointed by it

View Answer


15. Choose the best one - prior to using a pointer variable

A. It should be declared.
B. It should be initialized
C. It should be both declared and initialized.
D. None of the above.

View Answer


16. Which of the following statements are correct about the given program?

#include <stdio.h>
int main()
{
    printf("%p", main());
    return 0;
}

A. Prints garbage value infinite times
B. Error
C. Runs infinite times without printing anything
D. None of the above

View Answer


17. What is the output of this program?

#include <stdio.h>
void fun(int a, ...)
{
    printf("%d ", a);
}
 
int main()
{
    fun(1,2,3,4);
    fun(5,6,7,8,9);
    return 0;
}

A. 1 5
B. 2 5
C. 5 1
D. Compilation Error

View Answer


18. What is the meaning of using static before function declaration?

		   
static int demo(int a, int b)
{
    return (a + b);
}

A. Access to static functions is restricted to the file where they are declared
B. Static means nothing, sum() is same without static keyword.
C. Function need not to be declared before its use
D. None of the above

View Answer


19. What is the output of this program?

		   
#include <stdio.h>
int demo()
{
  static int i = 0;  
  printf("%d ",i++);
}
int main()
{
  for(int j = 0 ; j < 5 ; j++ )
  {
      demo();
  }
}

A. 0 0 0 0 0
B. 1 1 1 1 1
C. 1 2 3 4 5
D. 0 1 2 3 4

View Answer


20. What is the output of this program?

#include <stdio.h>
int test() 
{
  static int n = 10;
  return n--;
}
 
int main()
{
  for(test(); test(); test())
    printf("%d ", test());
  return 0;
}

A. 7 4 1
B. 8 5 2
C. Infinite loop
D. Compilation Error

View Answer


21. What is the output of this program?

int main()
{
  void test(), temp();
  temp();
}
void test()
{
  printf("2 ");
}
void temp()
{
  printf("1 ");
  test();
} 

A. 1 0
B. 0 1
C. Compile time error as foo is local to main
D. Compile time error due to declaration of functions inside main

View Answer


22. What is the output of this program?

#include <stdio.h>
void main()
    {
        test();
        void test()
        {
            printf("1");
        }
    }

A. 1
B. Compilation Error
C. Run Time Error
D. None of the above

View Answer


23. What is the output of this program?

#include <stdio.h>
void test(int * , int *);
void main()
{
  int a = 5 , b = 6;
  test(&a,&b);
  printf("%d %d",a,b);
}
void test(int *p, int *q)
{
  *p = *p * *q;
  *q = *p / *q;
  *p = *p / *q;
}

A. 30 5
B. 6 5
C. 5 6
D. None of the above

View Answer


24. What is the output of this program?

#include <stdio.h>
void test(char**);

int main()
{
    char *argv[] = {"a", "b", "c", "d"};
    test(argv);
    return 0;
}
void test(char **p)
{
    char *m;
    m = (p+= sizeof(int))[-2];
    printf("%s", m);
}

A. a
B. b
C. c
D. d

View Answer


25. What is the output of this program?

#include <stdio.h>
int main()
{
 char *ptr = "Hello";
 printf("%c", *&*&*ptr);
 return 0;
}

A. H
B. Compilation Error
C. Run Time Error
D. Garbage Value

View Answer


26. What is the output of this program?

#include <stdio.h>
void test(int *a, int *b) 
{ 
  a = b; 
  *a = 15; 
} 
int x = 10, y = 20; 
int main() 
{ 
  test(&x, &y); 
  printf("%d %d", x, y);
  return 0; 
}

A. 15 15
B. 10 15
C. 10 20
D. 15 20

View Answer


27. What does the following statment mean?

    int (*ptr)[5];

A. ptr is an array of 5 integers
B. ptr is a pointer to an array of 5 integers
C. ptr is array of pointers to 5 integers
D. ptr is an pointer to array

View Answer


28. What is the output of this program?

  
#include <stdio.h> 
int main()
{
int a = 5;
void *ptr = &a ;
printf("%f", *(float*)ptr);
return 0;
}

A. 5
B. 5
C. 0
D. 0

View Answer


29. What is the output of the given code ?

#include <stdio.h>
void main()
{
int a = 0 ;     
int *const ptr = &a ; 
printf("%p ", ptr);
ptr++;
printf("%p ", ptr);
}

A. 0 1
B. compilation Error
C. Run Time Error
D. None of the above

View Answer


30. What is the output of this program?

#include <stdio.h>
void main()
{
int a = 5 ;
int *b = &a ;
int **c = &b ;
printf("%d %d %d", a, *b, **c);
}

A. 5 garbage value garbage value
B. 5 5 garbage value
C. 5 5 5
D. Error

View Answer


31. What is the output of this program?

#include <stdio.h>
void main()
{
int arr[3] = {1, 2, 3};
int *ptr = arr;
int **temp = &ptr ; 
printf("%p %p", *temp, arr);
}

A. Same Address
B. Different Address
C. 1 2
D. 2 3

View Answer


32. The pointer ptr points to which string?

char *ptr;
char myString[]="letsfind";
ptr=myString
ptr+=5;

A. find
B. ind
C. letsf
D. f

View Answer


33. What will be the output ?

void main()
{
char far *farther, *farthest;
printf("%d %d", sizeof(farther), sizeof(farthest));
}

A. 4 2
B. 2 2
C. 4 4
D. 2 4

View Answer


34. What is the output of this program?

#include <stdio.h>
void test(int * , int *);
void main()
{
  int a = 5 , b = 6;
  test(&a,&b);
  printf("%d %d",a,b);
}
void test(int *p, int *q)
{
  *p = *p * *q;
  *q = *p + *q;
  *p = *p - *q;
}

A. -6 36
B. 6 36
C. 36 6
D. -42

View Answer


35. Will the program compile?

#include<stdio.h>
int main()
{
    char str[5] = "Letsfind";
    return 0;
}

A. TRUE
B. FALSE
C. May Be
D. Can't Say

View Answer


36. Are the three declarations char **apple, char *apple[], and char apple[][] same?

A. TRUE
B. FALSE
C. May Be
D. Can't Say

View Answer


37. Is the NULL pointer same as an uninitialised pointer?

A. Yes
B. No
C. May Be
D. Can't Say

View Answer


38. Which of the following statements correct about k used in the below statement?

char ****k;

A. k is a pointer to a pointer to a pointer to a char
B. k is a pointer to a pointer to a pointer to a pointer to a char
C. k is a pointer to a char pointer
D. k is a pointer to a pointer to a char

View Answer


39. Is there any difference between the following two statements?

char *p=0;
char *t=NULL;

A. Yes
B. No
C. May Be
D. Can't Say

View Answer


40. Is this a correct way for NULL pointer assignment?

int i=0;
char *q=(char*)i;

A. Yes
B. No
C. May Be
D. Can't Say

View Answer






Also check :


Discussion



* You must be logged in to add comment.