Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 281–290 of 499
Topics in C Programming
Q.281 Medium Arrays & Strings
Consider the code: int *p; int arr[5] = {10, 20, 30, 40, 50}; p = arr; What is *(p+2)?
A 20
B 30
C 40
D 50
Correct Answer:  B. 30
EXPLANATION

p points to arr[0]. p+2 points to arr[2], which contains 30.

Take Test
Q.282 Medium Arrays & Strings
What will be the output?
char arr[] = "ABC";
printf("%d", sizeof(arr));
A 3
B 4
C Depends on compiler
D Runtime error
Correct Answer:  B. 4
EXPLANATION

sizeof includes the null terminator. "ABC" has 4 bytes (A, B, C, \0).

Take Test
Q.283 Medium Arrays & Strings
Which function is used to find the first occurrence of a character in a string?
A strstr()
B strchr()
C strtok()
D strrchr()
Correct Answer:  B. strchr()
EXPLANATION

strchr() finds the first occurrence of a character. strrchr() finds the last occurrence. strstr() finds substrings.

Take Test
Q.284 Medium Arrays & Strings
What is the time complexity of inserting an element at the beginning of an unsorted array?
A O(1) - Constant time
B O(n) - Linear time (need to shift all elements)
C O(log n) - Logarithmic time
D O(n²) - Quadratic time
Correct Answer:  B. O(n) - Linear time (need to shift all elements)
EXPLANATION

Inserting at the beginning requires shifting all n elements one position right, making it O(n). Insertion at the end is O(1) if space exists.

Take Test
Q.285 Medium Arrays & Strings
What happens when you try to modify a string literal in C?
A The modification succeeds and permanent change occurs
B Compile-time error is generated
C Runtime error (segmentation fault or undefined behavior)
D The string is automatically copied before modification
Correct Answer:  C. Runtime error (segmentation fault or undefined behavior)
EXPLANATION

String literals are stored in read-only memory. Attempting modification causes undefined behavior (often segmentation fault). This is why char *str = "text"; str[0]='T'; is dangerous.

Take Test
Q.286 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.

Take Test
Q.287 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.

Take Test
Q.288 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.

Take Test
Q.289 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.

Take Test
Q.290 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.

Take 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