C Programming — Arrays & Strings
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 41–50 of 100 questions in Arrays & Strings
Q.41 Medium Arrays & Strings
Consider: int arr[10]; int *ptr = arr; What does ptr[5] represent?
A The 5th element of array arr
B Address of the 5th element
C Value at address arr + 5*sizeof(int)
D Both A and C
Correct Answer:  D. Both A and C
EXPLANATION

ptr[5] is equivalent to *(ptr+5), which accesses the 5th element. Pointer arithmetic adjusts by the size of int.

Take Test
Q.42 Medium Arrays & Strings
What is the output of the following code?
char str[] = "GATE";
printf("%d", sizeof(str));
A 4
B 5
C 8
D Compilation error
Correct Answer:  B. 5
EXPLANATION

sizeof(str) returns 5 because the array includes 4 characters plus 1 null terminator.

Take Test
Q.43 Medium Arrays & Strings
Which of the following correctly reverses a string in-place?
A strrev(str);
B reverse(str);
C str_reverse(str);
D reversestr(str);
Correct Answer:  A. strrev(str);
EXPLANATION

strrev() is a non-standard but commonly used function (available in string.h in some compilers) that reverses a string in-place.

Take Test
Q.44 Medium Arrays & Strings
What happens when you try to modify a string literal in C?
char *str = "Hello";
str[0] = 'J';
A String is successfully modified to 'Jello'
B Undefined behavior or runtime error
C Compilation error
D String remains 'Hello'
Correct Answer:  B. Undefined behavior or runtime error
EXPLANATION

String literals are stored in read-only memory. Attempting to modify them causes undefined behavior or segmentation fault.

Take Test
Q.45 Medium Arrays & Strings
What is the correct way to declare a pointer to a character array?
A char *ptr[];
B char (*ptr)[];
C *char ptr[];
D char **ptr;
Correct Answer:  B. char (*ptr)[];
EXPLANATION

char (*ptr)[] declares ptr as a pointer to a character array. The parentheses are crucial for correct precedence.

Take Test
How many bytes does a 2D array int arr[3][4] occupy in memory?
A 12 bytes
B 24 bytes
C 48 bytes
D 16 bytes
Correct Answer:  C. 48 bytes
EXPLANATION

int occupies 4 bytes. Array size is 3×4 = 12 elements. Total: 12 × 4 = 48 bytes.

Take Test
Which function is used to find the length of a string in C?
A strlen()
B strsize()
C stringlen()
D getlength()
Correct Answer:  A. strlen()
EXPLANATION

strlen() is the standard library function defined in string.h that returns the length of a string excluding the null terminator.

Take Test
What is the maximum size of a string that can be stored in char str[50]?
A 49 characters plus null terminator
B 50 characters plus null terminator
C 50 characters without null terminator
D Unlimited characters
Correct Answer:  A. 49 characters plus null terminator
EXPLANATION

A char array of size 50 can store maximum 49 characters because the last position is reserved for the null terminator '\0'.

Take Test
Q.49 Medium Arrays & Strings
What does strtok(str, delim) return on each call until the string ends?
A The entire remaining string
B A pointer to the next token
C The delimiter character
D The length of the token
Correct Answer:  B. A pointer to the next token
EXPLANATION

strtok() returns a pointer to the next token separated by the delimiter. Returns NULL when no more tokens exist.

Take Test
What is the output?
int arr[] = {10, 20, 30, 40};
int *p = arr;
printf("%d", p[2]);
A 10
B 20
C 30
D 40
Correct Answer:  C. 30
EXPLANATION

p points to arr[0]. p[2] is equivalent to *(p+2), which points to arr[2] = 30.

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