Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 571–580 of 1,000
Topics in C Programming
Q.571 Hard Arrays & Strings
What is the main difference between char arr[] = "Test" and char *ptr = "Test"?
A arr is a modifiable array; ptr points to read-only string literal
B Both allocate same memory
C ptr uses more memory than arr
D No difference - both are equivalent
Correct Answer:  A. arr is a modifiable array; ptr points to read-only string literal
EXPLANATION

arr creates a modifiable array copy of the string. ptr points to a string literal (read-only in memory). Modifying *ptr leads to undefined behavior.

Test
Q.572 Hard Arrays & Strings
Which of the following is true about strcpy(dest, src)?
A It checks buffer overflow and is safe to use
B It copies src to dest without checking dest buffer size - potential buffer overflow
C It returns the length of copied string
D It requires both strings to be NULL-terminated
Correct Answer:  B. It copies src to dest without checking dest buffer size - potential buffer overflow
EXPLANATION

strcpy() doesn't check dest buffer size, making it unsafe. It can cause buffer overflow if src is larger than dest. Modern compilers recommend strncpy() or strlcpy().

Test
Q.573 Hard Arrays & Strings
Consider: int arr[3][4][5]. What is the size of arr[0][0]?
A 20 bytes (5 integers)
B 4 bytes (1 integer)
C 80 bytes (20 integers)
D 60 bytes (15 integers)
Correct Answer:  A. 20 bytes (5 integers)
EXPLANATION

arr[0][0] is a 1D array of 5 integers. Each int is 4 bytes, so total is 5×4=20 bytes.

Test
Q.574 Medium Arrays & Strings
Which string function modifies the original string in-place?
A strtok()
B strlen()
C strcpy()
D Both A and C
Correct Answer:  D. Both A and C
EXPLANATION

Both strtok() (modifies by replacing delimiters with '\0') and strcpy() (copies and overwrites destination) modify strings in-place.

Test
Q.575 Medium Arrays & Strings
What is the output of sizeof(arr)/sizeof(arr[0]) when arr is declared as int arr[10]?
A 10
B 40
C 4
D Depends on system architecture
Correct Answer:  A. 10
EXPLANATION

This expression calculates array length. sizeof(arr) gives total bytes (40 on 32-bit system), sizeof(arr[0]) gives bytes per element (4), so 40/4=10.

Test
Q.576 Medium Arrays & Strings
In a 2D array int matrix[4][5], which statement about memory layout is true?
A Elements are stored in row-major order (row by row)
B Elements are stored in column-major order (column by column)
C Elements are randomly scattered in memory
D Memory layout depends on the compiler version
Correct Answer:  A. Elements are stored in row-major order (row by row)
EXPLANATION

C uses row-major order for 2D arrays. matrix[0][0], matrix[0][1]...matrix[0][4], matrix[1][0]... are stored sequentially in memory.

Test
Q.577 Easy Arrays & Strings
What does strlen() function return for the string "C2025"?
A 5
B 6
C 4
D Undefined behavior
Correct Answer:  A. 5
EXPLANATION

strlen() counts characters before the null terminator. "C2025" has 5 characters, so strlen returns 5. The null terminator is not counted.

Test
Q.578 Medium Arrays & Strings
If str = "Hello", what is the value of str[5]?
A '\0' (null character)
B 'o'
C Garbage value
D Error - index out of bounds
Correct Answer:  A. '\0' (null character)
EXPLANATION

"Hello" has 5 characters, so valid indices are 0-4. Index 5 contains the null terminator '\0' that marks the end of the string.

Test
Q.579 Medium Arrays & Strings
What is the relationship between array name and pointer in C?
A Array name decays to a pointer to its first element in most contexts
B Array name is exactly equivalent to a pointer variable
C Array names and pointers have no relationship
D Array name is a constant pointer that can be modified
Correct Answer:  A. Array name decays to a pointer to its first element in most contexts
EXPLANATION

Array names decay to pointers to the first element in expressions, but they are not truly pointer variables. The array name cannot be reassigned.

Test
Q.580 Medium Arrays & Strings
Which of the following correctly declares and initializes a 2D array?
A int arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
B int arr[3][3] = {1,2,3,4,5,6,7,8,9};
C Both A and B are correct
D Neither A nor B is valid
Correct Answer:  C. Both A and B are correct
EXPLANATION

Both syntax forms are valid in C. Elements can be provided in nested braces or as a linear list, and they fill row by row.

Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips