Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Pointers Quiz

Total questions: 66

Worksheet time: 34mins

Name
Class
Date
1.

What does the dereference operator (*) do?

a)

It compares two pointers

b)

It retrieves the value at the address stored in a pointer

c)

It assigns a value to a pointer

d)

It creates a pointer

2.

What is the size of a pointer on a 64-bit system?

a)

2 bytes

b)

4 bytes

c)

8 bytes

d)

16 bytes

3.

What is a NULL pointer?

a)

A pointer that points to a valid memory location

b)

A pointer that does not point to any memory location

c)

A pointer that points to a function

d)

A pointer that points to an array

4.

What is a wild pointer?

a)

A pointer that points to a valid memory location

b)

A pointer that points to a function

c)

A pointer that has not been initialized

d)

A pointer that points to NULL

5.

What is a dangling pointer?

a)

A pointer that points to a valid memory location

b)

A pointer that points to a memory location that has been freed

c)

A pointer that points to NULL

d)

A pointer that has not been initialized

6.

What is pointer arithmetic?

a)

Comparing two pointers

b)

Incrementing or decrementing pointer addresses

c)

Assigning values to pointers

d)

Performing mathematical operations on pointer values

7.

How can you access array elements using pointers?

a)

By using the dereference operator only

b)

By using the sizeof operator

c)

By using pointer arithmetic

d)

By using the array name directly

8.

What is a constant pointer?

a)

A pointer that cannot be modified

b)

A pointer that points to a constant value

c)

A pointer that can be reassigned

d)

A pointer that points to a variable

9.

What is a function pointer?

a)

A pointer that points to an array

b)

A pointer that cannot be modified

c)

A pointer that points to a variable

d)

A pointer that stores the address of a function

10.

What is the purpose of the malloc() function?

a)

To allocate memory dynamically

b)

To free allocated memory

c)

To initialize memory

d)

To check memory size

11.

What does the free() function do?

a)

Allocates memory

b)

Frees allocated memory

c)

Initializes memory

d)

Checks memory size

12.

What happens if you dereference an uninitialized pointer?

a)

It will return 0

b)

It will return NULL

c)

It will cause a segmentation fault

d)

It will return a random value

13.

What is the output of printf("%p", ptr) if ptr is a pointer to an integer?

a)

The address of the integer

b)

The size of the integer

c)

The type of the integer

d)

The value of the integer

14.

What is the relationship between arrays and pointers in C?

a)

Pointers cannot point to arrays

b)

Array names act like pointers to the first element

c)

Arrays and pointers are the same

d)

Arrays cannot be accessed using pointers

15.

What is the purpose of the realloc() function?

a)

To allocate new memory

b)

To change the size of previously allocated memory

c)

To initialize memory

d)

To free memory

16.

What is the output of *ptr if ptr points to an integer variable with value 10?

a)

The address of the variable

b)

NULL

c)

0

d)

10

17.

What is the main advantage of using pointers?

a)

They are easier to understand

b)

They are faster than arrays

c)

They allow dynamic memory allocation

d)

They simplify code

18.

What is a pointer to a pointer?

a)

A pointer that points to an array

b)

A pointer that cannot be modified

c)

A pointer that points to another pointer

d)

A pointer that points to a variable

19.

What is the output of printf("%d", *(&var)) if var is an integer variable with value 5?

a)

The address of var

b)

NULL

c)

0

d)

5

20.

What is the effect of using an invalid pointer?

a)

It will have no effect

b)

It will return a default value

c)

It may cause a program crash

d)

It will return NULL

21.

What is the correct way to initialize a pointer?

a)

int *ptr = var;

b)

int *ptr = 0;

c)

int *ptr = NULL;

d)

int *ptr = &var;

22.

What does the & operator do in C?

a)

Declares a pointer variable

b)

Returns the address of a variable

c)

Dereferences a pointer

d)

Multiplies two variables

23.

How do you declare a pointer to an integer in C?

a)

int p;

b)

int *p;

c)

int &p;

d)

pointer int p;

24.

What does the * operator do when used with pointers?

a)

Declares a pointer

b)

Returns the address of a variable

c)

Dereferences a pointer to access the value

d)

Multiplies two values

25.

What is the output of the following code?

a)

5

b)

Address of c

c)

Garbage value

d)

Compilation error

26.

Which of the following statements is incorrect?

a)

pc = &c;

b)

*pc = c;

c)

pc = c;

d)

*pc = &c;

27.

Given the array declaration int x[5];, what does x represent?

a)

The value of the first element

b)

The address of the first element

c)

The size of the array

d)

An undefined value

28.

Which expression is equivalent to x[i]?

a)

*(x + i)

b)

x + i

c)

&x + i

d)

*x + i

29.

What is the output of the following code?

a)

1

b)

2

c)

3

d)

4

30.

What happens when you assign the address of a variable to a pointer?

a)

The pointer stores the value of the variable

b)

The pointer stores the address of the variable

c)

The variable becomes a pointer

d)

Compilation error

31.

Which of the following is a common mistake when working with pointers?

a)

Assigning an address to a pointer

b)

Dereferencing a pointer before assigning it an address

c)

Using & to get the address of a variable

d)

Using * to access the value pointed by a pointer

32.

Pointers refer to

a)

Memory Address

b)

Value in Memory

c)

All the above

33.

Computer memory locations are

a)

Bi linear

b)

Linear

c)

Non Linear

34.

Computer address values in reality are in

a)

Decimal

b)

Binary

c)

Hexadecimal

d)

C code

35.

One Byte is equal to

a)

8 bits

b)

4 bits

c)

2 bits

d)

1 bit

36.

An integer requires

a)

One byte of memory

b)

4 bytes of memory

c)

8 bytes of memory

37.

printf("%d", &C), prints

a)

value of C

b)

Address of C

c)

Error message

d)

None of the above

38.

If 5 is added to the address value 'A' of an integer variable the new address is

a)

A +5

b)

A+ 10

c)

A+ 20

d)

Data insufficient

39.

In a C Program if

int a = 5;

Int *ptr = &a;

then the printf statement with

&a, a, *ptr , ptr

a)

adrress, Value, Value, Adress

b)

address, value, value, value

c)

all address

d)

All values

40.

In a C Program if

int a = 5;

Int *ptr = &a;

printf ("%d" , ptr)

gives

a)

5

b)

address of a

c)

address of ptr

d)

none

41.

A double pointer points

a)

address of an integer

b)

address of a pointer

c)

value stored in the memory

d)

None

42.

In a C program,

int a = 20;

*ptr = &a;

**dptr = &ptr;

printf ("%d", **dptr);


prints

a)

address of a

b)

address of ptr

c)

value of a

d)

address of dptr

43.

What do the following declaration signify?


char *arr[10];

a)

arr is a array of 10 character pointers.

b)

arr is a array of function pointer.

c)

arr is a array of characters.

d)

arr is a pointer to array of characters.

44.

What is the output of C Program.?

int main()

{

char grade[] = {'A','B','C'};

printf("GRADE=%c, ", *grade);

printf("GRADE=%d", grade);

}

a)

GRADE=some address of array, GRADE=A

b)

GRADE=A, GRADE=some address of array

c)

GRADE=A, GRADE=A

d)

Compiler error

45.

What is the output of C program.?

int main()

{

char grade[] = {'A','B','C'};

printf("GRADE=%d, ", *grade);

printf("GRADE=%d", grade[0]);

}

a)

A A

b)

65 A

c)

65 65

d)

None of the above

46.

What is the output of C program with arrays and pointers.?

int main()

{

int a[3] = {20,30,40};

printf("%d", *(a+1));

}

a)

20

b)

30

c)

40

d)

Compiler error

47.

What is the output of following program?

# include <stdio.h>

void fun(int x)

{

x = 30;

}

int main()

{

int y = 20;

fun(y);

printf("%d", y);

return 0;

}

a)

30

b)

20

c)

Compiler Error

d)

Runtime Error

48.

Output of following program?

# include <stdio.h>

void fun(int *ptr)

{

*ptr = 30;

}

int main()

{

int y = 20;

fun(&y);

printf("%d", y);

return 0;

}

a)

20

b)

30

c)

Compiler Error

d)

Runtime Error

49.

Pointers refer to

a)

Memory Address

b)

Value in Memory

c)

All the above

50.

Computer memory locations are

a)

Bi linear

b)

Linear

c)

Non Linear

51.

Computer address values in reality are in

a)

Decimal

b)

Binary

c)

Hexadecimal

d)

C code

52.

One Byte is equal to

a)

8 bits

b)

4 bits

c)

2 bits

d)

1 bit

53.

printf("%d", &C), prints

a)

value of C

b)

Address of C

c)

Error message

d)

None of the above

54.

A double pointer points

a)

address of an integer

b)

address of a pointer

c)

value stored in the memory

d)

None

55.

What is the output of following program?

#include<stdio.h>

int main()

{

int *ptr, a=5;

ptr = &a;

*ptr += 1;

printf("%d, %d", *ptr, a);

return 0;

}

a)

5,5

b)

5,6

c)

6,5

d)

6,6

56.

The value printed by the following program is

a)

10

b)

20

c)

30

d)

40

57.

How do you declare a pointer to a function in C?

a)

func_ptr *function_name

b)

function_name *func_ptr

c)

func_ptr function_name

d)

function_name func_ptr

58.
What will be the output of the following C code?

void main() {
  int a[] = {1,2,3,4,5}, p;
  p = a;
  ++
p;
  printf("%d ", p);
p += 2;
  printf("%d ",
p);
}

a)

24

b)

34

c)

22

d)

23

59.
What is the output of the following C code?

  char *ptr;
  char mystring[] = "abcdefg";
  ptr = myString;
  ptr += 5;

a)

fg

b)

efg

c)

defg

d)

cdefg

e)

bcdefg

60.
What will be the output of the following C code?

void main() {
  char p;
  p = "Hello";
  printf("%c\n",
&*p);
}

a)

Hello

b)

H

c)

Some address will be printed

d)

None of these

61.
What will be the output of the program if the array begins at 1000 and each integer occupies 2 bytes?

void main() {
  int i = 10;
  void p = &i;
  printf("%f\n",
(float *)p);
}

a)

Error

b)

10

c)

0.0000000

d)

None of these

62.

In a C Program if

int a = 5;

Int *ptr = &a;

then the printf statement with

&a, a, *ptr , ptr

a)

adrress, Value, Value, Adress

b)

address, value, value, value

c)

all address

d)

All values

63.

In a C program,

int a = 20;

*ptr = &a;

**dptr = &ptr;

printf ("%d", **dptr);


prints

a)

address of a

b)

address of ptr

c)

value of a

d)

address of dptr

64.

What will be output?

int i=10;

int *p;

p=&i;

i+=5;

printf("\n i=%d *p=%d", i,*p)

a)

i=10, *p=10

b)

i=10, *p=15

c)

i=15, *p=15

d)

i=15, *p=10

65.

# include <stdio.h>

void fun(int *p){

*p = 10;

}

int main()

{

int y = 5;

fun(&y);

printf("%d", y);

return 0;

}

a)

10

b)

5

c)

error

d)

address

66.

int main()

{

int arri[] = {1, 2 ,3};

int *ptri = arri;

printf("%d ", sizeof(arri));

printf("%d ", sizeof(ptri));

return 0;

}

a)

3 3

b)

12 12

c)

12 4

d)

4 4