1.
Number 1 is a legal name for variables in C language.
Correct Answer
B. False
Explanation
The statement is false because in C language, variable names cannot start with a number. They must start with a letter or an underscore.
2.
Evaluate the following code. Which variable will be assigned the value 9? int length=9, width, height;
Correct Answer
A. Length
Explanation
The variable "length" will be assigned the value 9. This is because in the given code, the variable "length" is explicitly assigned the value 9, while the variables "width" and "height" are not assigned any values. Therefore, the only variable that will have a value assigned to it is "length", and that value is 9.
3.
The machine code is the same for computers designed by different manufacturers.
Correct Answer
B. False
Explanation
The statement is false because machine code is specific to the hardware architecture of a computer. Different computer manufacturers may use different hardware architectures, which means that the machine code for their computers will be different.
4.
Which of the following is NOT a strength of C language
Correct Answer
C. Object Oriented
Explanation
The given question asks for a strength of C language that is NOT present. The other options, Efficiency, Portability, and Flexibility, are all strengths of C language. However, Object Oriented is not a strength of C language. C is a procedural programming language and does not support object-oriented programming concepts such as inheritance, polymorphism, and encapsulation. Therefore, Object Oriented is the correct answer as it is not a strength of C language.
5.
Assembly language has a one-to-one relationship with machine code
Correct Answer
A. True
Explanation
Assembly language is a low-level programming language that is closely related to machine code. It uses mnemonics to represent machine instructions and has a one-to-one correspondence with the machine code instructions that the computer's processor can execute directly. This means that each assembly language instruction corresponds to a specific machine code instruction, making it easier for programmers to understand and write code that directly interacts with the computer's hardware. Therefore, the statement "Assembly language has a one-to-one relationship with machine code" is true.
6.
A typical high-level-language statement is equivalent to many machine-code instructions.
Correct Answer
A. True
Explanation
A typical high-level-language statement is equivalent to many machine-code instructions because high-level languages are designed to be more user-friendly and abstracted from the low-level details of the machine. High-level statements are often more concise and expressive, allowing programmers to achieve complex functionality with fewer lines of code. However, when the high-level code is compiled or interpreted, it is translated into multiple machine-code instructions that the computer can understand and execute. This translation process ensures that the high-level code is converted into the appropriate sequence of low-level instructions that the machine can process.
7.
What is the size of int in memory
Correct Answer
A. 4 bytes
Explanation
The size of an int in memory is typically 4 bytes. The int data type is used to store whole numbers, and on most systems, it is represented using 32 bits, which is equivalent to 4 bytes. This allows an int variable to hold values ranging from -2,147,483,648 to 2,147,483,647.
8.
What is the only function all C programs must contain?
Correct Answer
C. Main()
Explanation
The correct answer is "main()". In C programming, the main() function is the entry point of the program. It is the function where the program starts its execution and it must be present in every C program. The main() function typically contains the code that performs the desired tasks and logic of the program. Without the main() function, the program would not have a starting point and would not be able to execute any code.
9.
Which pair of punctuations is used to signal the beginning and end of a function in C?
Correct Answer
A. { and }
Explanation
In C programming, the pair of curly braces { and } is used to signal the beginning and end of a function. These braces enclose the body of the function, which contains the statements and declarations that define the function's behavior. The opening curly brace { indicates the start of the function, while the closing curly brace } marks the end of the function. This pair of punctuations is essential for defining the scope of the function and ensuring that the statements within it are executed together as a unit.
10.
Which of the following is not a correct variable type?
Correct Answer
B. Real
Explanation
The variable type "real" is not a correct variable type in most programming languages. The correct variable types in this context are float, int, and char. "Real" is not a commonly used variable type and is not recognized by most programming languages.
11.
In which standard library file is the function printf() located ?
Correct Answer
B. Stdio.h
Explanation
The function printf() is located in the stdio.h standard library file. This file contains the necessary declarations and definitions for input and output operations in C programming language.
12.
In order to properly use a variable...
Correct Answer
D. All of the above.
Explanation
The correct answer is "All of the above." This is because in order to properly use a variable, it must have a valid type, the variable name cannot be a keyword in the C syntax, and the variable name must begin with a letter or underscore. All three statements are necessary for using a variable correctly.
13.
Which operating system was C developed for?
Correct Answer
D. Unix
Explanation
C was developed for the Unix operating system. Unix was one of the earliest operating systems, developed in the 1960s, and C was created in the early 1970s as a systems programming language specifically for use with Unix. C and Unix were developed in tandem and had a strong influence on each other. The portability and efficiency of C made it a popular choice for programming on Unix systems, and it continues to be widely used for system-level programming and development of operating systems.
14.
What punctuation must each statement have at the end of the line ?
Correct Answer
D. ;
Explanation
Each statement must have a semicolon (;) at the end of the line.
15.
What is the output of following C program?#include int main () { int a=6; int b; b=a*7/3-4*2; printf("a=%d, b=%d\n", a, b); return 0;}
Correct Answer
D. A=6, b=6
Explanation
The output of the given C program is "a=6, b=6". This is because the program first assigns the value 6 to the variable "a". Then, the expression "a*7/3-4*2" is evaluated. In this expression, the multiplication and division have higher precedence than subtraction. So, first "a*7" is calculated as 6*7=42, then "42/3" is calculated as 14, and finally "14-4*2" is calculated as 14-8=6. Therefore, the value of "b" is 6. Finally, the values of "a" and "b" are printed using the printf function.
16.
What is the output of the following program?main(){ int a = -5, b = -4; printf("%d",a/b);}
Correct Answer
D. 1
Explanation
The program is dividing the value of variable a (-5) by the value of variable b (-4) using integer division. Integer division truncates the decimal part of the result, so -5 divided by -4 equals 1. Therefore, the output of the program is 1.
17.
What is the output of the following program?void main (){int x = 10;printf ("x = %d, y = %d", x, x*2-4);}
Correct Answer
D. X = 10, y = 16
Explanation
The program prints "x = 10, y = 16" as the output. This is because the value of x is 10, and the expression x*2-4 evaluates to 16. The printf statement then prints the values of x and y, which are 10 and 16 respectively.
18.
Which line of the following program will generate error? (The number at the left of each line indicate line number and are not part of the program code)1 #include23 int main () 4 {5 height =4;6 int height;7 printf("The height is %d\n", height);8 return 0;9 }
Correct Answer
B. Ling 5 and 6
Explanation
The line 5 and 6 will generate an error because the variable "height" is being used before it is declared. In C programming, variables must be declared before they are used. So, in this case, the program will not be able to recognize the variable "height" when it is assigned a value in line 5.
19.
Which number is returned at the end of function to indicate that the program executes successfully?
Correct Answer
B. 0
Explanation
The number 0 is returned at the end of the function to indicate that the program executes successfully. This is a common convention in programming, where a return value of 0 typically signifies successful execution.
20.
Which symbol is used for address of the variable?
Correct Answer
C. &
Explanation
The symbol "&" is used to represent the address of a variable in programming languages. It is commonly used in languages like C and C++ to access the memory address of a variable. By using the "&" symbol, the programmer can manipulate and work with the memory address of a variable, allowing for more advanced operations and functionality within the program.
21.
In a C program, the first statement that will be executed is:
Correct Answer
B. The first executable statement of the main() function.
Explanation
In a C program, the first statement that will be executed is the first executable statement of the main() function. The main() function is the entry point of a C program, and execution starts from the first statement inside this function. Other parts of the program, such as comments or functions defined after the main() function, will not be executed until they are called or invoked from within the main() function.
22.
To incldue a file that you created on your onw, single quotation marks are used. For example: #include 'myfile.h'
Correct Answer
B. False
Explanation
In C++ programming, to include a file that you created on your own, double quotation marks should be used instead of single quotation marks. Therefore, the correct answer is False.
23.
Compiler translate the middle-level and high-level language programs into equivalent assembly language programs.
Correct Answer
B. False
Explanation
The statement is false because compilers translate high-level language programs into equivalent machine code, not assembly language programs. Assembly language is a low-level programming language that is specific to a particular computer architecture and is usually written by humans, whereas machine code is the binary representation of instructions that can be directly executed by the computer's hardware.
24.
Which of the following is used to indicate that the function does not return any value?
Correct Answer
A. Void
Explanation
The keyword "void" is used in programming to indicate that a function does not return any value. It is commonly used in languages like C, C++, and Java to specify that a function is a "void" function, meaning it performs certain operations but does not produce any output or return any result.
25.
The type of a variable determines the operations the compiler will allow for the variable.
Correct Answer
A. True
Explanation
The statement is true because the type of a variable determines the kind of data it can hold and the operations that can be performed on it. For example, if a variable is declared as an integer type, it can only hold integer values and arithmetic operations like addition, subtraction, and multiplication can be performed on it. On the other hand, if a variable is declared as a string type, it can hold text data and operations like concatenation can be performed on it. The compiler uses the variable's type information to enforce type safety and ensure that only valid operations are performed on the variable.