Unit 5 - Practice Quiz

CSE101 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which operator is used to return the memory address of a variable?

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

2 What is the correct syntax to declare a pointer to an integer?

A. int ptr;
B. int *ptr;
C. int &ptr;
D. ptr int;

3 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

4 What is the result of the expression *ptr if ptr is a pointer holding the address of variable x?

A. The address of x
B. The value of x
C. The address of ptr
D. The size of x

5 What is a Null Pointer?

A. A pointer that points to a specific valid address.
B. A pointer that has not been initialized.
C. A pointer pointing to address 0 or explicitly assigned NULL.
D. A pointer pointing to a deleted variable.

6 Which of the following defines a Void Pointer?

A. A pointer that points to nothing.
B. A generic pointer that can point to any data type.
C. A pointer that returns a null value.
D. A pointer used for arithmetic operations.

7 What happens if you try to dereference a void pointer without typecasting?

A. It returns 0.
B. It works normally.
C. It causes a compilation error.
D. It returns garbage value.

8 A pointer that points to a memory location that has been deleted (freed) is called:

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

9 What is a Wild Pointer?

A. A pointer pointing to NULL.
B. An uninitialized pointer.
C. A pointer pointing to a function.
D. A pointer stored in heap memory.

10 If int *p points to address 1000 and sizeof(int) is 4 bytes, what is the value of p + 1?

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

11 Which of the following arithmetic operations is NOT allowed on pointers?

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

12 What is the result of subtracting two pointers of the same type?

A. The sum of their addresses
B. The number of elements between the two pointers
C. The multiplication of addresses
D. A pointer to the middle element

13 Consider the declaration int a[5] = {10, 20, 30, 40, 50};. What is *(a + 2) equal to?

A. 10
B. 20
C. 30
D. Address of 30

14 Which of the following is equivalent to arr[i]?

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

15 What is the primary difference between an array name and a pointer variable?

A. Array name is a constant pointer; pointer variable is not.
B. Pointer variable cannot store address of array.
C. Array name cannot be dereferenced.
D. There is no difference.

16 When passing a pointer to a function, what method of parameter passing is simulated?

A. Call by value
B. Call by reference
C. Call by name
D. Call by constant

17 Which library header must be included to use malloc, calloc, and free?

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

18 What is the return type of the malloc function?

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

19 How does calloc differ from malloc regarding memory initialization?

A. malloc initializes memory to zero; calloc does not.
B. calloc initializes memory to zero; malloc contains garbage values.
C. Both initialize memory to zero.
D. Neither initializes memory.

20 Which function is used to resize a previously allocated memory block?

A. malloc
B. calloc
C. realloc
D. memalloc

21 What is the syntax for calloc?

A. ptr = calloc(byte_size);
B. ptr = calloc(num_elements, element_size);
C. ptr = calloc(element_size, num_elements);
D. ptr = calloc(num_elements);

22 What happens if you do not free dynamically allocated memory before the program terminates?

A. Compilation error
B. Memory Leak
C. Segmentation fault
D. Nothing, OS always frees it instantly

23 What value do malloc and calloc return if the memory allocation fails?

A. -1
B. 0
C. NULL
D. Garbage value

24 In C, strings are represented as:

A. A primitive data type 'string'
B. An array of characters terminated by a null character
C. An object of String class
D. A pointer to an integer

25 Which character serves as the string terminator in C?

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

26 What is the output size of sizeof("Hello")?

A. 5
B. 6
C. 4
D. 8

27 Which function is unsafe to use for reading strings because it does not check buffer length?

A. scanf
B. fgets
C. gets
D. getchar

28 What is the difference between char s[] = "Hello"; and char *p = "Hello";?

A. No difference.
B. s is modifiable, p points to a string literal which is likely read-only.
C. p is modifiable, s is read-only.
D. s allows pointer arithmetic, p does not.

29 Which format specifier is used to read a string using scanf?

A. %c
B. %s
C. %d
D. %f

30 Which library function calculates the length of a string?

A. strlength()
B. size()
C. strlen()
D. strcount()

31 What does strcpy(dest, src) do?

A. Concatenates src to dest
B. Compares dest and src
C. Copies the content of src to dest
D. Returns the length of src

32 Which header file is required for string manipulation functions like strcpy and strcmp?

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

33 What does strcmp(s1, s2) return if s1 and s2 are identical?

A. 1
B. -1
C. 0
D. Non-zero

34 If strcat(s1, s2) is executed, what is the result?

A. s1 is appended to s2
B. s2 is appended to s1
C. s1 and s2 are copied to a new string
D. s1 is overwritten by s2

35 What will strlen("Code") return?

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

36 How do you correctly convert a character digit '5' to the integer 5?

A. '5' + 0
B. (int)'5'
C. '5' - '0'
D. atoi('5')

37 What function is used to convert a string to a long integer?

A. atoi
B. atol
C. itoa
D. strtod

38 What logic converts an uppercase letter ch to lowercase?

A. ch - 32
B. ch + 32
C. ch * 2
D. ch / 2

39 Which function searches for the first occurrence of a character in a string?

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

40 What does strstr(haystack, needle) do?

A. Finds a character in a string
B. Concatenates two strings
C. Finds the first occurrence of substring 'needle' in 'haystack'
D. Compares two strings

41 What is the difference between printf("%s", str) and puts(str)?

A. No difference.
B. printf adds a newline automatically, puts does not.
C. puts adds a newline automatically, printf does not.
D. puts can format output, printf cannot.

42 Consider char *str = "Hello";. What is valid?

A. str[0] = 'h';
B. str = "World";
C. *str = 'M';
D. None of the above

43 What is the purpose of void * in malloc?

A. To allocate memory for void types only
B. To act as a generic pointer type that can be cast to any type
C. To indicate the function returns nothing
D. To create a null pointer

44 What is the priority of *ptr++?

A. Increment ptr, then dereference
B. Dereference ptr, then increment the value pointed to
C. Dereference ptr, then increment the pointer
D. Undefined

45 Which of the following creates a pointer to a pointer (Double Pointer)?

A. int **p;
B. int &p;
C. int p;
D. int p**;

46 Why is free() necessary in dynamic memory allocation?

A. To initialize the memory
B. To return memory to the heap for reuse
C. To clear the contents of the variables
D. To delete the pointer variable

47 How do you read a string with spaces using scanf?

A. scanf("%s", str);
B. scanf("%[^
]s", str);
C. scanf("%s space", str);
D. scanf("% line", str);

48 If int arr[] = {1, 2, 3}; and int *p = arr;, what is p[1]?

A. 1
B. 2
C. 3
D. Address of 2

49 Which operator accesses a member of a structure using a pointer to that structure?

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

50 What is the output of printf("%d", *&a) if a = 10?

A. Address of a
B. 10
C. Garbage
D. Error