c programming pointer functions mcq, Quizzes of C programming

c programming pointer functions mcq

Typology: Quizzes

2014/2015

Uploaded on 01/21/2026

vivek-sharma-46
vivek-sharma-46 🇮🇳

2 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
A.O.C. INSTITUTE
100 Detailed MCQs: Arrays and
Pointers in C
1. What is the size of a pointer variable in C?
A) Always 2 bytes
B) Always 4 bytes
C) Depends on the architecture (32-bit vs
64-bit)
D) Depends on the data type it points to
2. If int *p = 1000;, what is the value of p + 2
(assume sizeof(int) = 4)?
A) 1002
B) 1004
C) 1008
D) 1016
3. [GATE 2005] Which of the following is
equivalent to *(a + i)?
A) a[i]
B) i[a]
C) both A and B
D) none of the above
4. A pointer that is not initialized to any valid
memory address is called:
A) Null Pointer
B) Wild Pointer
C) Dangling Pointer
D) Void Pointer
5. What is the output of printf("%d", *&*&p);
where p is an integer?
A) Address of p
B) Value of p
C) Error
D) Garbage value
6. Which operator is used to get the address
of a variable?
A) *
B) ->
C) &
D) &&
7. [ISRO] If char *ptr; and ptr points to
address 0x2000, what is ptr + 1?
A) 0x2001
B) 0x2004
C) 0x2008
D) 0x2002
8. A pointer that points to nothing is a:
A) Wild pointer
B) Null pointer
C) Void pointer
D) Constant pointer
9. [Concept] Can we subtract two pointers?
A) Yes, if they point to the same array
B) Yes, always
C) No, never
D) Yes, but it returns a float
10. What is the result of adding two pointers?
A) A new address
B) Sum of their indices
C) Illegal operation (Error)
D) Difference in bytes
11. An array name in C behaves like:
A) A variable pointer
B) A constant pointer
C) A null pointer
D) A function
12. What is the output of the following? int
arr[5] = {1, 2, 3}; printf("%d", arr[4]);
A) Garbage
B) 0
C) Error
D) 3
13. [GATE 2011] If int arr[3][3] is defined, how
is arr[1][2] accessed using pointers?
pf3
pf4
pf5
pf8

Partial preview of the text

Download c programming pointer functions mcq and more Quizzes C programming in PDF only on Docsity!

100 Detailed MCQs: Arrays and

Pointers in C

  1. What is the size of a pointer variable in C? A) Always 2 bytes B) Always 4 bytes C) Depends on the architecture (32-bit vs 64-bit) D) Depends on the data type it points to
  2. If int *p = 1000;, what is the value of p + 2 (assume sizeof(int) = 4)? A) 1002 B) 1004 C) 1008 D) 1016
  3. [GATE 2005] Which of the following is equivalent to *(a + i)? A) a[i] B) i[a] C) both A and B D) none of the above
  4. A pointer that is not initialized to any valid memory address is called: A) Null Pointer B) Wild Pointer C) Dangling Pointer D) Void Pointer
  5. What is the output of printf("%d", &&p); where p is an integer? A) Address of p B) Value of p C) Error D) Garbage value
  6. Which operator is used to get the address of a variable? A) * B) ->

C) &

D) &&

  1. [ISRO] If char *ptr; and ptr points to address 0x2000, what is ptr + 1? A) 0x B) 0x C) 0x D) 0x
  2. A pointer that points to nothing is a: A) Wild pointer B) Null pointer C) Void pointer D) Constant pointer
  3. [Concept] Can we subtract two pointers? A) Yes, if they point to the same array B) Yes, always C) No, never D) Yes, but it returns a float
  4. What is the result of adding two pointers? A) A new address B) Sum of their indices C) Illegal operation (Error) D) Difference in bytes
  5. An array name in C behaves like: A) A variable pointer B) A constant pointer C) A null pointer D) A function
  6. What is the output of the following? int arr[5] = {1, 2, 3}; printf("%d", arr[4]); A) Garbage B) 0 C) Error D) 3
  7. [GATE 2011] If int arr[3][3] is defined, how is arr[1][2] accessed using pointers?

A) ((arr + 1) + 2) B) *(arr + 1 + 2) C) ((arr + 2) + 1) D) (arr + 1) + 2

  1. The index of the first element in a C array is always: A) 1 B) - C) 0 D) Random
  2. int a[5]; Where is the memory for this array allocated if declared inside a function? A) Heap B) Stack C) Code segment D) Data segment
  3. Which of the following is an invalid array declaration? A) int a[] = {1, 2, 3}; B) int a[5]; C) int a[5] = {1, 2, 3, 4, 5, 6}; D) int a[0];
  4. [NIELIT] What does sizeof return for an array passed to a function? A) Total size of array in bytes B) Size of the pointer to the array C) Number of elements D) Error
  5. Multi-dimensional arrays in C are stored in: A) Row-Major order B) Column-Major order C) Diagonal order D) Random order
  6. int *p[10]; This represents: A) An array of 10 pointers B) A pointer to an array of 10 integers C) A function returning a pointer D) A pointer to a pointer
  7. int (*p)[10]; This represents: A) An array of 10 pointers B) A pointer to an array of 10 integers C) A double pointer D) Syntax error
  8. char *s = "Hello"; The string "Hello" is stored in: A) Stack B) Read-only data segment C) Heap D) Register
  9. What is the output? char str[] = "C-Exam"; printf("%d", sizeof(str)); A) 6 B) 7 C) 5 D) 8
  10. Which of the following can modify the string? A) char *s = "Hello"; s[0] = 'M'; B) char s[] = "Hello"; s[0] = 'M'; C) Both A and B D) None
  11. [ISRO] printf("%s", "Computer" + 3); prints: A) Computer B) puter C) Com D) mputer
  12. The \0 character is called: A) Null pointer B) Null terminator C) Blank space

A) 1 byte B) sizeof(int) bytes C) 4 bytes always D) Depends on value of p

  1. [NIELIT] Which of the following is used to prevent a pointer from changing the address it holds? A) const int *p; B) int * const p; C) static int *p; D) extern int *p;
  2. int *p = NULL; Dereferencing p results in: A) 0 B) Runtime Error (Segmentation Fault) C) Compiler Error D) Garbage value
  3. int a[] = {10, 20, 30}; int *p = a; printf("%d", *p++); A) 10 B) 11 C) 20 D) Error
  4. int a[] = {10, 20, 30}; int p = a; printf("%d", (p)++); A) 10 B) 11 C) 20 D) 30
  5. int a[] = {10, 20, 30}; int p = a; printf("%d", ++p); A) 11 B) 20 C) 10 D) 21
  6. int a[2][2] = {1, 2, 3, 4}; printf("%d", *a[1]);

A) 1

B) 2

C) 3

D) 4

  1. [GATE] int a[] = {1, 2, 3, 4, 5}; int *p = a + 2; printf("%d", p[1]); A) 3 B) 4 C) 5 D) 2
  2. void f(int *p) { *p = 5; } In main: int x=10; f(&x); x is: A) 10 B) 5 C) 0 D) Garbage
  3. int a = 5; void *ptr = &a; printf("%d", (int)ptr); A) Address of a B) 5 C) Error D) Garbage
  4. char *c = "GATE"; char **cp = &c; printf("%s", *cp); A) G B) GATE C) Address D) Error
  5. int arr[5]; What is &arr + 1? A) Address of second element B) Address after the end of the entire array C) Address of first element + 1 byte D) Syntax error
  6. int p; p = (int)malloc(sizeof(int)); This is:

A) Static allocation B) Dynamic allocation C) Automatic allocation D) Register allocation

  1. [GATE] int a[10][20]; The address of a[i][j] is (base address B, size W): A) B + (i * 20 + j) * W B) B + (j * 10 + i) * W C) B + (i * 10 + j) * W D) B + (i + j) * W
  2. What is NULL in C? A) Macro for 0 B) A special character C) A keyword D) A function
  3. int *p; What is sizeof(p)? A) 4 or 8 B) 2 C) Depends on int size D) 1
  4. [ISRO] int arr[] = {1, 2, 3}; int *p = arr; What is *(p + 1)? A) 1 B) 2 C) 3 D) Address
  5. int a = 10; int *p = &a; int **q = &p; Value of **q is: A) Address of a B) Address of p C) 10 D) Error
  6. [GATE] Which is correct to declare a pointer to a function returning int and taking int? A) int f(int); B) int (f)(int); C) int f*(int); D) int (f)(int);
  7. char s[] = "ABC"; s++; Result: A) "BC" B) Error (Array name is constant) C) "B" D) "A"
  8. char *s = "ABC"; s++; Result: A) Pointer points to "B" B) Error C) "BC" D) "C"
  9. int a[5] = {1}; Values of other 4 elements: A) Garbage B) 1 C) 0 D) 5
  10. sizeof("Hello") vs strlen("Hello"): A) 6 and 5 B) 5 and 5 C) 6 and 6 D) 5 and 6
  11. [NIELIT] A function returns more than one value using: A) Return statement B) Pointers C) Static variables D) Header files
  12. int *p; p = calloc(5, sizeof(int)); initialized to: A) Garbage B) 0 C) 1

A) Returns NULL or unique pointer B) Always Error C) Crash D) 1 byte

  1. Pointer that can point to any function: A) Generic pointer B) Callback pointer C) Function pointer D) Void pointer
  2. [ISRO] int a = 320; char p = (char)&a; (Little Endian) *p is: A) 320 B) 64 C) 0 D) 1
  3. int *p; and *p = 10; without malloc or &a: A) Correct B) Undefined Behavior (Wild Pointer) C) Compiler Error D) Value 10 in memory
  4. Array is passed to function by: A) Value B) Reference (Pointer) C) Copying D) Stack
  5. int a[5]; a++ is: A) Illegal (L-value required) B) Legal C) Increments first element D) Points to next element
  6. &a[0] is same as: A) a B) *a C) &a D) a[0]
    1. [GATE] How many stars are printed? char s = "123"; while(s++) printf("*"); A) 3 B) 4 C) 2 D) Infinite
    2. void * can be assigned to int *: A) Only with cast B) Without cast in C C) Never D) Only in C++
    3. scanf("%d", p); where p is int *: A) Correct B) Should be &p C) Should be *p D) Error
    4. int (*p[5])(int); is: A) Array of 5 function pointers B) Pointer to 5 functions C) Function returning array D) Error
    5. Pointer comparison p < q is valid if: A) Both are same type B) Both point to same array C) Always D) Never
    6. strcat(s1, s2): A) Appends s2 to s B) Appends s1 to s C) Merges to new string D) Deletes s
    7. [NIELIT] Max size of an array is limited by: A) Compiler B) RAM/Memory C) Data type

D) Operating System

  1. int a[5] = {0}; A) All elements are 0 B) First is 0, others garbage C) Error D) Only first is 0
  2. double arr[10]; sizeof(arr); is: A) 10 B) 80 C) 40 D) 8
  3. char *s; s = "A"; A) Correct B) Incorrect C) S is char D) Error
  4. *p is called: A) Indirection/Dereferencing B) Address-of C) Pointing D) Scaling
  5. Offset of a[i] is: A) i * sizeof(type) B) i C) sizeof(type) D) i + 1
  6. int arr[5] = {1, 2, 3, 4, 5}; printf("%d", 2[arr]); A) 3 B) 2 C) Error D) Garbage
  7. p = malloc(10); p = malloc(20); A) Memory Leak B) Resizes to 20 C) Error D) Frees 10
  8. const int * const p; A) Constant pointer to constant int B) Pointer is constant C) Int is constant D) Error
  9. Binary search on array requires: A) Sorted elements B) Random elements C) Only integers D) Pointers
  10. [GATE] Pointer to a structure member: A) ptr->member B) ptr.member C) *ptr.member D) ptr&member
  11. Best way to avoid memory leaks: A) Use free() B) Use malloc() only C) Use static D) Restart program