Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

94 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 61–70 of 94
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.61 Easy C Programming
What will be the output of: char *s = "Hello"; printf("%d", strlen(s));
A 5
B 6
C 4
D Error
Correct Answer:  A. 5
EXPLANATION

strlen() counts characters excluding the null terminator. "Hello" has 5 characters, so strlen(s) returns 5.

Test
Q.62 Easy C Programming
What is the size of an empty structure in C?
A 0 bytes
B 1 byte
C 4 bytes
D 8 bytes
Correct Answer:  B. 1 byte
EXPLANATION

An empty structure in C has a size of 1 byte. This is to ensure each structure instance has a unique address in memory.

Test
Q.63 Easy C Programming
Which of the following is a correct way to initialize a 1D array in C?
A int arr[5] = {1, 2, 3, 4, 5};
B int arr[] = {1, 2, 3, 4, 5};
C int arr[5];
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

All three methods are valid. Option A initializes with size 5, option B auto-determines size from initialization, and option C declares without initialization.

Test
Q.64 Easy C Programming
What does the sizeof() operator return?
A The address of a variable
B The number of bytes occupied by a data type or variable
C The maximum value a variable can hold
D The number of bits in a variable
Correct Answer:  B. The number of bytes occupied by a data type or variable
EXPLANATION

sizeof() is a unary operator that returns the number of bytes occupied by a variable or data type in memory.

Test
Q.65 Easy C Programming
Which operator is used to access the value at an address in C?
A &
B *
C ->
D .
Correct Answer:  B. *
EXPLANATION

The * operator is the dereference operator that accesses the value at a memory address. The & operator gets the address of a variable.

Test
Q.66 Easy C Programming
What is the correct syntax to declare a constant in C?
A const int x = 10;
B int const x = 10;
C constant int x = 10;
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

Both 'const int x = 10;' and 'int const x = 10;' are valid ways to declare constants in C. The const keyword can appear before or after the type.

Test
Q.67 Easy C Programming
Which header file is required for using the printf() function?
A cstdlib.h
B stdio.h
C string.h
D math.h
Correct Answer:  B. stdio.h
EXPLANATION

stdio.h (Standard Input/Output header) contains declarations for printf(), scanf(), and other I/O functions.

Test
Q.68 Easy C Programming
What is the purpose of the return statement in a C function?
A To exit the program
B To return a value to the caller and exit the function
C To declare variables
D To create a loop
Correct Answer:  B. To return a value to the caller and exit the function
EXPLANATION

The return statement is used to exit a function and return a value (if any) to the calling function. If the function has return type void, no value is returned.

Test
Q.69 Easy C Programming
Which of the following is used to declare a constant in C?
A constant int x = 5;
B const int x = 5;
C final int x = 5;
D immutable int x = 5;
Correct Answer:  B. const int x = 5;
EXPLANATION

In C, the 'const' keyword is used to declare constants. Once a const variable is initialized, its value cannot be changed. Options A, C, and D are not valid C syntax.

Test
Q.70 Easy C Programming
What will be the output of: int a = 10; int b = 20; int c = a + b; printf("%d", c);?
A 10
B 30
C 20
D Error
Correct Answer:  B. 30
EXPLANATION

Variable 'a' is initialized to 10, 'b' is initialized to 20. When c = a + b, c becomes 10 + 20 = 30. Therefore, printf outputs 30.

Test
IGET
IGET AI
Online · Exam prep assistant
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