Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Chapter: 15
Q221:
What does the array name 'y' represent in C?
A. A) A pointer to the first element
B. B) The size of the array
C. C) A constant pointer to the array’s memory address
D. D) A variable storing the array's length
Correct Answer: C
Chapter: 15
Q222:
What happens when you increment a pointer variable in C?
A. A) It moves to the next memory location of the same data type
B. B) It moves to the next integer location in memory
C. C) It increments by one byte irrespective of the data type
D. D) It increments by four bytes always
Correct Answer: A
Chapter: 15
Q223:
Which of the following statements is true about pointer arithmetic?
A. A) Adding two pointers is allowed in C
B. B) Subtracting two pointers gives the number of bytes between them
C. C) Incrementing a pointer by 1 always increments it by 1 byte
D. D) Subtracting pointers gives the number of elements between them
Correct Answer: D
Chapter: 15
Q224:
How is the null character used in a C string?
A. A) To signify the end of a string
B. B) To indicate the start of a string
C. C) To separate strings in a character array
D. D) To initialize an array of characters
Correct Answer: A
Chapter: 15
Q225:
What is the result of the following pointer subtraction operation: yptr2 - yptr1 where yptr1 points to y[0] and yptr2 points to y[3]?
A. A) 3
B. B) 12
C. C) 4
D. D) 1
Correct Answer: A
Chapter: 15
Q226:
Which of the following correctly increments the value pointed to by a pointer?
A. A) (*ptr)++
B. B) ptr++
C. C) ++(*ptr)
D. D) Both A and C
Correct Answer: D
Chapter: 15
Q227:
What will be the output of the following code snippet?
A. A) 10
B. B) 11
C. C) 12
D. D) Compilation error
Correct Answer: B
Chapter: 15
Q228:
In the context of pointer and array relationship, what is true about the statement yptr = y?
A. A) yptr can be assigned to any memory address
B. B) yptr is assigned the address of the first element of the array y
C. C) yptr is a constant pointer
D. D) y can be reassigned to point to a different memory address
Correct Answer: B
Chapter: 15
Q229:
What does the expression *(yptr + 5) do if yptr is a pointer to the beginning of an integer array?
A. A) Accesses the fifth element in the array
B. B) Increments the value of yptr by 5
C. C) Assigns the value 5 to yptr
D. D) Accesses the value of the sixth element in the array
Correct Answer: A
Chapter: 15
Q230:
How does pointer comparison work in C?
A. A) Pointers can only be compared if they point to the same data type
B. B) Pointers can be compared to determine their relative addresses
C. C) You cannot compare pointers directly; you need to dereference them first
D. D) Pointers can be compared only if they point to the same array
Correct Answer: B
Chapter: 16
Q231:
What does the statement char myName[] = "Full Name"; do?
A. Creates a char array and populates it with "Full Name"
B. Creates a pointer to a char with "Full Name"
C. Creates a char array but does not initialize it
D. Creates a pointer to a char but does not initialize it
Correct Answer: A
Chapter: 16
Q232:
What is the primary difference between char myName[] = "Full Name"; and char *myNamePtr = "Full Name";?
A. myName is a constant pointer, and myNamePtr can be changed
B. myName can be changed, and myNamePtr is constant
C. Both myName and myNamePtr can be changed
D. Neither myName nor myNamePtr can be changed
Correct Answer: A
Chapter: 16
Q233:
What does multi + 1 point to in a two-dimensional array char multi[5][10];?
A. The second element of the first row
B. The first element of the second row
C. The second row as a whole
D. The third row
Correct Answer: B
Chapter: 16
Q234:
How can you access the element at the second row and third column of multi[5][10] using pointers?
A. *(*(multi+1)+2)
B. *(multi+2+1)
C. **(multi+2)
D. *(*multi+2)
Correct Answer: A
Chapter: 16
Q235:
How does the *multi expression behave for a two-dimensional array?
A. Points to the first element of the first row
B. Points to the first row
C. Points to the first element of the first column
D. Points to the last element of the array
Correct Answer: B
Chapter: 16
Q236:
In the context of pointers to pointers, what does a double dereference provide?
A. Access to the value of the variable
B. Access to the address of the variable
C. Access to the address of the pointer
D. Access to the pointer itself
Correct Answer: A
Chapter: 16
Q237:
What is the main advantage of using an array of pointers for character strings?
A. It allows variable length strings without wasting space
B. It simplifies the handling of fixed-size strings
C. It makes the code more complex
D. It uses less memory than a fixed-size array
Correct Answer: A
Chapter: 16
Q238:
What does the argc variable represent in command-line arguments?
A. The number of command-line arguments
B. The name of the program
C. The value of the first argument
D. The pointer to the argument list
Correct Answer: A
Chapter: 16
Q239:
How do you convert a command-line argument from a string to an integer?
A. Use atoi() function
B. Use itostr() function
C. Use strtoi() function
D. Use int() function
Correct Answer: A
Chapter: 16
Q240:
What is the purpose of the srand() function in random number generation?
A. To initialize the random number generator with a seed
B. To generate a random number
C. To get the current time
D. To reset the random number generator
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now