1.
To declare a header file you use #include headerfile.h
Correct Answer
A. True
Explanation
To include a header file in a C++ program, the correct syntax is #include "headerfile.h". This line of code tells the compiler to insert the contents of the specified header file into the program at that point. Therefore, the statement "To declare a header file you use #include headerfile.h" is true.
2.
The printf function is located in the following header files:
Correct Answer(s)
A. Stdio.h
D. Iostream
Explanation
The correct answer is stdio.h and iostream. These two header files contain the necessary functions and declarations for input and output operations in C and C++. stdio.h is the standard input/output library in C, while iostream is the input/output stream library in C++.
3.
To declare a constant variable you use the following statement:
Correct Answer
C. Const
Explanation
The correct answer is "const". In programming, the "const" keyword is used to declare a constant variable, which is a variable whose value cannot be changed once it is assigned. By using "const", you can ensure that the value of the variable remains constant throughout the program, preventing accidental modifications and providing clarity to other programmers who read the code.
4.
Which is the correct way to declare an array?
Correct Answer
A. Int a[12];
Explanation
The correct way to declare an array is "int a[12];". This statement declares an array named "a" of size 12, where each element is of type integer. The square brackets "[]" are used to indicate that "a" is an array, and the number inside the brackets specifies the size of the array.
5.
The following is a correct do while statement:
do{
printf("enter a number: ");
scanf("%d", &i);
}
while(i <= 12)
Correct Answer
B. False
Explanation
The programmer forgot the semicolon ( ; )
should be like so:
do{
statements;
}while(expression);
6.
Is this correct?
#include
int main()
{
int i = 0;
int j = 2;
if(i < j)
printf("i variable is smaller than j variable");
return 0;
}
Correct Answer
A. True
Explanation
The given code snippet is correct. It includes the necessary header file, defines the main function, and declares and initializes two integer variables i and j. The if statement checks if i is less than j, and if it is, it prints the message "i variable is smaller than j variable". Since the value of i is 0 and the value of j is 2, the condition i < j is true, and the message is printed. Finally, the main function returns 0 to indicate successful execution. Therefore, the correct answer is True.
7.
The pow function is located in the _______ header file
Correct Answer
math.h
cmath
Explanation
The pow function is located in the math.h and cmath header files. These header files are used in C and C++ programming languages to include mathematical functions and constants. The pow function specifically is used to calculate the power of a number, where the first argument is the base and the second argument is the exponent. By including the math.h or cmath header file, developers can access and use the pow function in their code.
8.
A return statement returns a value to the function from which it is called from
Correct Answer
A. True
Explanation
A return statement in programming is used to end the execution of a function and return a value back to the function that called it. This allows the function to pass data or results back to the calling function. Therefore, the given statement that a return statement returns a value to the function from which it is called from is true.
9.
C is an Object Oriented Programming Language
Correct Answer
B. False
Explanation
The given statement "C is an Object Oriented Programming Language" is false. C is not an object-oriented programming language. It is a procedural programming language that focuses on procedures and functions rather than objects and classes. Object-oriented programming languages like C++ and Java have features like encapsulation, inheritance, and polymorphism, which C lacks.
10.
Learning C is a good way to learn C++
Correct Answer
A. True
Explanation
Learning C is a good way to learn C++ because C and C++ have similar syntax and share many concepts. C++ is an extension of the C language, so understanding C will provide a solid foundation for learning C++. Both languages use similar data types, control structures, and functions. Additionally, learning C first allows one to understand the fundamentals of programming before diving into the more complex features of C++. Overall, learning C can help individuals grasp the basics and principles that are essential for programming in C++.