Unit 5 - Practice Quiz

CSE101

1 Which operator is used to retrieve the address of a variable in C?

A. *
B. &
C. ->
D. %

2 What is the output of the following code snippet? int x = 10; int *p = &x; printf("%d", *p);

A. Address of x
B. 10
C. Garbage value
D. Compilation Error

3 Which of the following best describes a Wild Pointer?

A. A pointer pointing to NULL
B. A pointer that has been freed
C. A pointer that is declared but not initialized
D. A pointer to a void type

4 A pointer that points to a memory location that has been deleted or freed is called a __.

A. Null Pointer
B. Void Pointer
C. Dangling Pointer
D. Wild Pointer

5 What is the size of a pointer variable in a 64-bit architecture?

A. 2 bytes
B. 4 bytes
C. 8 bytes
D. Depends on the data type it points to

6 Which of the following statements about void pointers is true?

A. They can be dereferenced directly.
B. Pointer arithmetic is allowed directly on void pointers in standard C.
C. They can point to any data type.
D. They are automatically initialized to NULL.

7 If int *ptr contains address 1000 and sizeof(int) is 4 bytes, what is the value of ptr + 1?

A. 1001
B. 1004
C. 1002
D. 1010

8 Which of the following operations is ILLEGAL for pointers?

A. Subtracting two pointers of the same type
B. Adding an integer to a pointer
C. Adding two pointers
D. Comparing two pointers

9 What does the expression *ptr++ do?

A. Increments the pointer, then returns the value at the new address
B. Increments the value being pointed to
C. Returns the current value pointed to, then increments the pointer
D. It is a syntax error

10 Consider int arr[5] = {1, 2, 3, 4, 5}; int *p = arr;. What is the value of *(p + 3)?

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

11 How do you declare a pointer to a constant integer?

A. int const *ptr;
B. const int *ptr;
C. int * const ptr;
D. Both A and B

12 Which header file is required for dynamic memory management functions like malloc and calloc?

A. <stdio.h>
B. <stdlib.h>
C. <memory.h>
D. <string.h>

13 What is the return type of malloc()?

A. int *
B. char *
C. void *
D. null

14 Which function is used to allocate memory and initialize all bytes to zero?

A. malloc()
B. calloc()
C. realloc()
D. alloc()

15 What is the correct syntax to allocate an array of 10 integers using malloc?

A. int ptr = (int )malloc(10);
B. int ptr = (int )malloc(10 * sizeof(int));
C. int ptr = malloc(10 int);
D. int ptr = (int )calloc(10 * sizeof(int));

16 What is the purpose of the free() function?

A. To clear the values in memory
B. To release dynamically allocated memory back to the heap
C. To delete a pointer variable
D. To resize memory

17 If realloc() fails to resize the memory, what happens to the original block?

A. It is freed automatically
B. It remains unchanged
C. It becomes a wild pointer
D. The program crashes immediately

18 Which specific character is used to terminate a string in C?

A. '.'
B. '\0'
C. '\n'
D. '0'

19 What is the output of sizeof("Hello") vs strlen("Hello")?

A. 5 and 5
B. 6 and 5
C. 6 and 6
D. 5 and 6

20 Which function is safer than gets() for reading a string from the user?

A. scanf()
B. getch()
C. fgets()
D. getchar()

21 What does the function strcmp(str1, str2) return if str1 is lexicographically greater than str2?

A.
B. A negative integer
C. A positive integer
D. NULL

22 Which library function is used to copy one string to another?

A. strcopy()
B. strcpy()
C. strncpy()
D. memcpy()

23 What is the result of 'c' - 'a' in C?

A. Error
B. 2
C. 99
D. Variable

24 Consider char *str = "Programming";. What is *(str + 3)?

A. 'P'
B. 'r'
C. 'o'
D. 'g'

25 What happens if you define char str[] = "Hello"; and then try str++?

A. Pointer moves to 'e'
B. Pointer moves to 'l'
C. Compilation Error
D. Undefined Behavior

26 Which function appends one string to the end of another?

A. stradd()
B. strcat()
C. strappend()
D. strncat()

27 When passing a one-dimensional array to a function, what is actually passed?

A. The value of the first element
B. The value of all elements
C. The address of the first element
D. The address of the last element

28 Which of the following creates a "Memory Leak"?

A. Allocating memory and forgetting to free it
B. Accessing memory after freeing it
C. Using uninitialized pointers
D. Allocating 0 bytes

29 What is the difference between calloc and malloc arguments?

A. malloc takes two args, calloc takes one
B. malloc takes one arg, calloc takes two
C. Both take one arg
D. Both take two args

30 If int a = 5; int *p = &a;, which expression effectively doubles the value of a?

A. p = p * 2;
B. p = p * 2;
C. &a = &a * 2;
D. a = &p * 2;

31 What does strrev() do?

A. Reverses a string
B. Repeats a string
C. Reserves memory for string
D. Returns string revision

32 Which format specifier is used to print a memory address (pointer) in printf?

A. %d
B. %u
C. %x
D. %p

33 Given char *s = "Hello"; s[0] = 'M';. What happens?

A. String becomes "Mello"
B. Compiler Error
C. Runtime Error / Undefined Behavior
D. Nothing changes

34 How do you calculate the length of a string without using library functions?

A. Use sizeof
B. Loop until \n is found
C. Loop until \0 is found
D. Subtract start address from end address

35 Which standard function converts a string representation of a number to an integer (e.g., "123" to 123)?

A. stroint()
B. atoi()
C. itoa()
D. to_int()

36 What is the equivalent pointer expression for arr[i]?

A. *arr + i
B. *(arr + i)
C. &arr + i
D. arr + i

37 If ptr is a null pointer, what does free(ptr) do?

A. Causes a runtime error
B. Does nothing
C. Crashes the system
D. Prints an error message

38 Which is the correct way to declare a pointer to a function taking two integers and returning void?

A. void *func(int, int);
B. void (*func)(int, int);
C. void *func(int, int);
D. void *(func)(int, int);

39 What is the value of NULL typically defined as in C?

A. -1
B. 1
C. 0 or (void *)0
D. Infinite

40 In the expression char str[20];, str acts as a:

A. Constant pointer
B. Variable pointer
C. Void pointer
D. Null pointer

41 What is the output of printf("%d", sizeof(char *)); on a 32-bit machine?

A. 1
B. 2
C. 4
D. 8

42 Which function allows searching for a character within a string?

A. strstr()
B. strchr()
C. strcat()
D. strtok()

43 What is the correct logic to swap two numbers using pointers pa and pb?

A. temp = pa; pa = pb; pb = temp;
B. temp = pa; pa = pb; pb = temp;
C. pa = pb;
D. pa = *pb;

44 If int arr[] = {10, 20}; int *p = arr;, what is the result of ++*p?

A. p points to 20
B. Value at arr[0] becomes 11
C. Value at arr[0] becomes 20
D. Syntax error

45 Which of the following creates a 2D array dynamically (rows=R, cols=C)?

A. malloc(R C sizeof(int))
B. malloc(R) then malloc(C) loop
C. An array of pointers where each points to an allocated integer array
D. All of the above

46 What happens if strcat is used without ensuring the destination string has enough space?

A. Automatic resizing
B. Buffer Overflow
C. Truncation of string
D. Null pointer exception

47 To read a string with spaces (e.g., "New York"), which conversion specifier should be used in scanf?

A. %s
B. %[^
]
C. %c
D. %string

48 Which pointer type is returned by pointer subtraction?

A. int *
B. ptrdiff_t
C. void *
D. size_t

49 What is the purpose of tolower() function in character arithmetic?

A. Converts string to lowercase
B. Converts a single character to lowercase
C. Checks if character is lower case
D. Lowers the memory address

50 Given char s[] = "World";, what is the valid way to assign a new string?

A. s = "Hello";
B. strcpy(s, "Hello");
C. s[] = "Hello";
D. s.value = "Hello";