Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

303 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 171–180 of 303
Topics in C Programming
Q.171 Easy Arrays & Strings
Consider a 2D array declared as: int matrix[3][4]. How many elements does it have?
A 3
B 4
C 7
D 12
Correct Answer:  D. 12
EXPLANATION

A 2D array with dimensions 3x4 has 3*4 = 12 total elements.

Take Test
Q.172 Easy Arrays & Strings
What does the following code do? strcpy(dest, src);
A Compares two strings
B Copies string src to dest
C Concatenates two strings
D Finds length of string
Correct Answer:  B. Copies string src to dest
EXPLANATION

strcpy() copies the contents of the source string to the destination string.

Take Test
Q.173 Easy Arrays & Strings
Which of the following is NOT a valid string initialization?
A char str[] = "Program";
B char str[10] = {'P','r','o','g'};
C char str[10]; str = "Program";
D char *str = "Program";
Correct Answer:  C. char str[10]; str = "Program";
EXPLANATION

Array names are constant pointers and cannot be reassigned. Direct assignment to char array after declaration is invalid.

Take Test
Q.174 Easy Arrays & Strings
What will be the output of strlen("Hello") in C?
A 4
B 5
C 6
D Error
Correct Answer:  B. 5
EXPLANATION

strlen() returns the length of the string excluding the null terminator '\0'. "Hello" has 5 characters.

Take Test
Q.175 Easy Arrays & Strings
What is the correct way to declare a 1D array of 10 integers in C?
A int arr[10];
B int arr(10);
C int arr{10};
D int [10]arr;
Correct Answer:  A. int arr[10];
EXPLANATION

In C, arrays are declared with the syntax: datatype arrayname[size]. Option A follows the correct syntax.

Take Test
Q.176 Easy Functions
Consider the function declaration: void func(int x); and later in the code: int result = func(5);. What will be the compilation result?
A Compilation error because func returns void but is assigned to an int variable
B Compilation warning but will compile successfully; result will be undefined
C Successful compilation and result will be 5
D Runtime error will occur
Correct Answer:  A. Compilation error because func returns void but is assigned to an int variable
EXPLANATION

A void function cannot return a value. Attempting to assign the return value of a void function to a variable will cause a compilation error in standard C compilers.

Take Test
Q.177 Easy Functions
What is the difference between declaring a function and defining a function?
A Declaration specifies the function signature; definition includes the function body
B They are the same thing in C
C Definition comes before declaration
D Declaration includes the function body; definition does not
Correct Answer:  A. Declaration specifies the function signature; definition includes the function body
EXPLANATION

A declaration tells the compiler about the function's signature (return type, name, parameters); a definition provides the actual implementation (function body).

Take Test
Q.178 Easy Functions
Which keyword is used to pass arguments by reference in C?
A ref
B Pointers are used to simulate pass-by-reference
C reference
D &reference
Correct Answer:  B. Pointers are used to simulate pass-by-reference
EXPLANATION

C does not have a 'ref' keyword like C++. Pointers are used to achieve pass-by-reference semantics in C by passing the address of a variable.

Take Test
Q.179 Easy Functions
What is the scope of a static function in C?
A Global scope across all files
B Limited to the file in which it is defined
C Limited to the function block only
D Available to all functions in the current block
Correct Answer:  B. Limited to the file in which it is defined
EXPLANATION

A static function has internal linkage and is limited to the file in which it is defined. It cannot be accessed from other translation units.

Take Test
Q.180 Easy Functions
Which of the following is a correct function prototype in C?
A int func();
B func int();
C int func(void) { }
D func (void) int;
Correct Answer:  A. int func();
EXPLANATION

A function prototype must have the return type first, followed by the function name and parameter list in parentheses. Option A is the correct syntax.

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