C Programming Final
2 Bytes is equal to _______ Bits A. 16 B. 8 C. 2 D. 14
Answer: 16
Which of the following is not a valid relational operator? A. =< B. >= C. > D. <
Answer: =<
Which of the following is the standard way to scan a float variable x? floatx; A. scanf("%d", &x); B. scanf("%.2f", &x); C. scanf("%f", &x); D. scanf("%f",x);
Answer: scanf("%f", &x)
Which of the following is the correct syntax to define a constant variable in C? A. #define <NAME> value B. #define <NAME> data_type = value C. #define data_type <NAME> = value D. None of the above
Answer: #define <NAME> value
Which of the following formats is used to display a float to two decimal places? Assume: float radius = 1.4535; Expected output: 1.45 A. %.3f B. %.f C. %.2d D. %.2f
Answer: %.2f
Which of the following is the correct syntax to change the data type (type casting) of a variable? A. (data_type) variable B. variable = data_type C. variable (data_type) D. none of the above
Answer: (data_type) variable
The extension of the source file for a C Program is: A. .exe B. .java C. .h D. .c
Answer: .c
What is the extension of the source file for a C program: A. .zip B. .c C. .java D. .txt
Answer: .c
The standard libraries in C have a header file with which of the following extensions? A. .exe B. .h C. .c D. .obj
Answer: .h
Which of the following is a correct comment in a C program? A. /* this is a comment */ B. ** this is a comment ** C. # this is a comment D. */ this is a comment */
Answer: /* this is a comment */
What will be the value of sum after running the following segment of code? int sum = 0; int n =1; while(n>=3) { sum = sum + n; n = n + 1; } printf("The sum value is: %d , sum); A. 0 B. 6 C. 4 D. 3
Answer: 0
What will be the value of the variable "a" when running the following statements? int y = 3; int x = 4; int a = y < x || y % 2 == 0; A. 1 B. 0 C. true D. false
Answer: 1
What will be the value of the variable c on execution of the following code segment? int a = 10; int b = 10; int c = 0; if (a >= b) { c = a * b; } else { c = a + b; } A. 100 B. 0 C. 20 D. 10
Answer: 100
1 Gigabyte is equal to _______ Megabyte A. 8 B. 1024 C. 999 D. 1000
Answer: 1024
What will be the output of the following code: #include<stdio.h> int main() { int num = 13; ++num; printf("%d", num++); return 0; } A. 12 B. 14 C. 15 D. 13
Answer: 14
What is the value of x in the following code segment: int x = 9+6/ 2*4; A. 1.8 B. 8 C. 21 D. 1
Answer: 21
What will be stored in the variable "a" after int a = 12; int b = 7; a = 3* ++b; A. 21 B. 10 C. 24 D. 8
Answer: 24
What should be the output: int main() { int a = 10/3; printf("%d", a); return 0; } A. 3.33 B. 3.0 C. 3 D. 0
Answer: 3
What will be the value of the variable B after running the following code segment? int B = 1; int loop = 1; while (loop < 8) { B = B + 1 loop = loop + 2; } printf("%d", B); A. 7 B. 5 C. 6 D. 1
Answer: 5
What will be the output of the following code: #include<stdio.h> int main() { float val = 3.5 + 4.5; printf("%.2f", val); return 0; } A. 8.0 B. 8.00 C. Compiler error D. 8
Answer: 8.00
Which of the following is not a logical operator A. || B. ! C. & & D. ==
Answer: ==
Which of the following is the correct precedence of the operators? A. Relational operators, Logical operators, Arithmetic operators B. Logical operators, Arithmetic operators, Relational operators C. Arithmetic operators, Logical operators, Relational operators D. Arithmetic operators, Relational operators, Logical operators
Answer: Arithmetic operators, Relational operators, Logical operators
In the given code segment, what is the scope of the variable c? int a = 10; if(a <= 10) { int c; c = a * 10; } A. It doesn't have a scope B. Block scope C. Local scope D. Global scope
Answer: Block scope
Which of the following is not an example of Operating System A. CPU B. Windows C. Android D. Linux
Answer: CPU
Which of the following is not a pre-test loop? A. While loop B. Do-While loop C. For loop D. All of the above
Answer: Do-While loop
Which of the following is not a pre-test loop? A. While loop B. Do-While loop C. for loop D. All the given loops are pre-test loops
Answer: Do-While loop
Which of the following operator checks whether the two operand values are same or different? A. None of the above B. Equality operator (==) C. Assignment operator (=) D. Relational operator (<, >, <=, >=)
Answer: Equality operator (==)
What is the output of the following code fragment? int finalGrade = 59; if (finalGrade < 60) { printf("Fail!"); } else { printf("Pass!"); } A. Syntax error B. Compilation error C. Pass! D. Fail!
Answer: Fail!
A byte is the smallest unit of data in a computer? A. True B. False
Answer: False
A function that returns a value should have a void return datatype. A. True B. False
Answer: False
A function that returns no output has a return type of int. A. True B. False
Answer: False
A syntax error is not a type of compile- time error A. True B. False
Answer: False
A variable name in C can start with a digit or special character A. True B. False
Answer: False
C is not a case sensitive language: A. True B. False
Answer: False
Default case is required in the switch statement A. True B. False
Answer: False
If the variable a = 4 and variable b = 3 what will be the output of a <= b A. True B. False
Answer: False
In a c program, "%" symbol is an arithmetic operator which is used to calculate percentage of 2 numbers A. True B. False
Answer: False
Preprocessor, is a software that goes through the C program after compilation? A. True B. False
Answer: False
Printf function is used to read user input A. True B. False
Answer: False
The code in the function is enclosed between [ ... ] A. True B. False
Answer: False
The following code will generate a random number between 0 and 5 (5 is included): int num; num = rand() % 5; A. True B. False
Answer: False
The value of constant variable can be changed in any where in the code A. True B. False
Answer: False
Value of the named constant can be changed in the code A. True B. False
Answer: False
While loop is a post-test loop. A. True B. False
Answer: False
How many times will the following code print "Welcome to C Programming"? int count = 0; while(count < 10) { printf("Welcome to C Programming"); } A. 8 B. 10 C. 9 D. Infinite number of times
Answer: Infinite number of times
What will be the output of the following code fragment? int age = -1; if (age < 18 && age >= 0) { printf("User is under 18"); } else if (age >= 18 && age < 21) { printf("User is under 21"); } else if (age >= 21) { printf("User is over 21"); } else { printf("Invalid age entered"); } A. User is under 18 B. Compilation error C. Invalid age entered D. Syntax error
Answer: Invalid age entered
Variable declared in a function has what type of scope A. General Scope B. Local Scope C. Block Scope D. Global Scope
Answer: Local Scope
The C expression "if (a==10 || b==20) {...}" can be re-written as? A. if (a == 10) || if (b == 20) {...} B. if (a == 10) {...} if (b == 20) {...} C. if (a == 10) {...} else if (b == 20) {...} D. None of the above
Answer: None of the above
What is the output of the following code fragment? int finalGrade = 80; if (finalGrade < 60) { printf("Fail!"); } else { printf("Pass!"); } A. Fail! B. Pass! C. Syntax error D. Compilation error
Answer: Pass!
What will be the outcome of the following code segment int option = 1; switch(option) { case 1: printf("Red"); case 2: printf("Blue"); case 3: printf("Green"); break; default: printf("Invalid Option!"); } A. Red Blue Green B. Red C. Invalid Option! D. Red Blue
Answer: Red Blue Green
What will be displayed by the following code segment int sum = 0; for (int i = 0; i <= 10; i++) { sum = sum + sum; } printf("Sum = %d" , sum); A. Sum = 10 B. Sum = 15 C. Sum = 0 D. Sum = 4
Answer: Sum = 0
Which of the following is not a type of loop? A. Do-While B. For C. Switch-Case D. While
Answer: Switch-Case
What will be the output of the following code: #include<stdio.h> int main() { printf("Hello\nWorld!") return 0 } A. Hello World! B. Hello World! C. Hello World! D. There will be no output, there is a syntax error in the code
Answer: There will be no output, there is a syntax error in the code
A Boolean data type has only two values: A. True B. False
Answer: True
A const keyword is used to define a constant in c. Example: const int SIZE = 100; A. True B. False
Answer: True
A variable is identified by its name, data type and scope. A. True B. False
Answer: True
Assume: int a = 10; int b = 10; Evaluate the following expression: a <= b || b <= a A. True B. False
Answer: True
C Is not an object oriented programming language? A. True B. False
Answer: True
C is a case sensitive programming language: A. True B. False
Answer: True
Evaluate the following logical expression: !(age > 25) Assume: int age = 22; A. True B. False
Answer: True
Every program statement must end with a semicolon ";" A. True B. False
Answer: True
Hardware is the tangible part of the computer system A. True B. False
Answer: True
If the variable a = 15 and variable b = 8 what will be the output of a >= b A. True B. False
Answer: True
If the variable a = 4 and variable b = 7 what will be the output of b == 7 A. True B. False
Answer: True
In C language, true is stored as 1 while false is stored as 0 A. True B. False
Answer: True
In C, the program execution begins with the main() function A. True B. False
Answer: True
In C, the rand() function generates a random number between 0 and MAX integer A. True B. False
Answer: True
Omitting the break statement for a case in switch will cause the statements within the next case to be executed A. True B. False
Answer: True
Preprocessor directives start with # (Ex. #include<stdio.h>) A. True B. False
Answer: True
Program execution in C begins with the main() function? A. True B. False
Answer: True
Source Code is the computer program written by a programmer? A. True B. False
Answer: True
The logical NOT operator (!) reverses the truth of a Boolean expression A. True B. False
Answer: True
Will the following code generate a syntax error: #include <stdio.h> int main() { printf ("CNIT 10500 is awesome!") return 0; } A. True B. False
Answer: True
You can change the data type of a variable is an expression by casting as in the following: (data_type) variable; A. True B. False
Answer: True
Which of the following statements takes the execution out of the loop A. Break; B. printf (); C. scanf (); D. All of the given statements take execution out of loop
Answer: break;
Which of the following statements takes the execution out of the loop? A. printf (); B. break; C. scanf (); D. All of the above
Answer: break;
Which of the following is the correct syntax to define a constant variable in C? A. const data_type NAME = value; B. data_type NAME = const value; C. const NAME = data_type; D. none of the above
Answer: const data_type NAME = value;
Which of the following choices will correctly call the function display() in the following main function. void display(int grade, float gpa) { printf("Students grade is %d \n" , grade); printf("Students gpa is %.2f \n", gpa); } int main() { int grade; float gpa; printf("Enter students grade and gpa"); scanf("%d %f", &grade, &gpa); ------------------------------ // invoke the function here return 0; } A. display(5,7,8); B. display(4.5); C. display(75, 3.5); D. display();
Answer: display (75, 3.5);
Which of the following is the correct syntax of if statement? A. (expression) if { Statements... } B. if (expression) { Statements... } C. if { expression } D. if expression { Statements... }
Answer: if (expression) { Statements... }
Which of the following is a correct if expression to check if the variable temp is between 55 and 70? A. if (temp >= 55 && temp <= 70) B. if (temp >= 55 || temp <= 70) C. if (temp == 55 && temp == 70) D. if (temp <= 55 && temp >= 70)
Answer: if (temp >= 55 && temp <= 70)
Which of the following statements is a correct function prototype of the function compute? function: int compute (int num1, int num2) { return (num1/num2); } A. int compute (num1, num2); B. compute (int num1, int num2); C. compute (); D. int compute (int num1, int num2);
Answer: int compute(int num1, int num2);
Which of the following functions is used in all the C programs? A. program() B. system() C. start() D. main()
Answer: main()
Which of the following functions must exist in all C program: A. start() B. system() C. main() D. program()
Answer: main()
Which of the following is a valid invocation for the function myFunction(): void myFunction(){ printf("Midterm Exam for CNIT-105"); } A. myFunction(); B. myFunction; C. myFunction("CNIT105 is awesome");
Answer: myFunction();
In the following code segment choose the condition that will replace the ------- in the following code. The goal of this code is to keep prompting the user until the user enters a number greater than or equal to 0 int num; do{ printf(); scanf("%d", &num); } while (-------); A. num >= 0 B. num > 0 C. num < 0 D. num <= 0
Answer: num < 0
Which of the following statement will raise 2 to the power of 8 and store the result in the variable value? Assume: float value; A. value = 2^8; B. value = pow (2,8); C. value = 2*8; D. value = pow (8,2);
Answer: value = pow (2,8);
Which of the following operators is used to compare two variables in C? Assume: int var1, var2; A. var1 = var2 B. var1 == var2 C. var1 ?: var2 D. var1 := var2
Answer: var1 == var2
Which of the following is the symbol for logical AND? A. ! B. || C. && D. &
Answer: &&
Assume that the goal is to partially fill an array with test scores (between 0 and 100 both inclusive) by prompting the user in a loop. Which of the following can be used as a sentinel value to stop the data entry? A. 100 B. -1 C. 1 D. 0
Answer: -1
What will be the output of the following code int n; for(n = 1; n <= 10; n++) { printf("%d" , n); } A. 0123456789 B. 12345678910 C. 123456789 D. 1234567891011
Answer: 1 2 3 4 5 6 7 8 9 10
What is the outcome of the following loop? int num = 1; while (num <= 100) { num = num + 1; } printf("%d", num); A. This loop will not execute at all B. This is an infinite loop C. 100 D. 101
Answer: 101
What will be the value of variable len after the execution of following code? int main () { char name[ ] = "I Love CNIT105!"; int len; len = strlen(len); } A. 14 B. 13 C. 12 D. 15
Answer: 15
When was 'C' developed? A. 1970's B. 1980's C. 1960's D. 2000's
Answer: 1970's
What will be stored in variable result by the following statements? float result; result = 13 / 5; A. 2.0 B. 2.6 C. 3.0 D. unknown
Answer: 2.0
What will be displayed by execution of the following code? char name[ ] = "Andy Wang" ; printf ("%s" , name); A. Wang B. Andy C. Runtime error D. Andy Wang
Answer: Andy Wang
What will be the output of the following code? int option = 1; switch(option) { case 1: printf("Computer"); case 2: printf("And "); case 3: printf("Information Technology!"); break; default: printf("Invalid Option!"); A. Computer And Information Technology! B. Computer C. Information Technology! D. And
Answer: Computer And Information Technology!
Which of the following is required to read or write to a file on the disk? A. int * ptr; B. FILE * ptr; C. File * ptr; D. FILE ptr;
Answer: FILE * ptr;
"C" is an object - oriented language A. True B. False
Answer: False
&d identifies is used to print or scan a variable of double-floating data type A. True B. False
Answer: False
A switch statement requires a default case A. True B. False
Answer: False
The "%d" identifier is used to print or scan a variable of double - floating data type A. True B. False
Answer: False
Variables declared inside a function have a global scope and can be used anywhere in the program A. True B. False
Answer: False
Identify the problem in the following code float compute(int a, int b) { float answer; answer = a / b; } A. Variable answer should be of type int B. Output type of the function should be int C. Function doesn't return anything D. There is nothing wrong with this function
Answer: Function doesn't return anything
What is the scope of a variable? A. It is the same as name of the variable B. It is the segment of the code where the variable can be used C. It is a location of the variable in RAM D. It is a data type of the variable
Answer: It is the segment of the code where the variable can be used
What is the outcome of the following segment of code? int option = 1; switch (option) { case 1: printf("Red \n"); case2: printf("Blue \n"); case3: printf("Green \n"); break; default: printf("Invalid option. \n"); } A. Red and Blue B. Red C. Red, Blue and Green D. Invalid option
Answer: Red, Blue and Green
How many time will the loop in the following code run int main() { int n = 1; int sum = 0; while(n <= 10) { sum = sum + n; } printf("Sum of numbers from 1 to 10 is: %d", sum); } A. The loop will not execute B. The loop will run infinite times C. The loop will run 10 times D. The loop will run 11 times
Answer: The loop will run infinite times
In "C" the program execution begins with which function? A. The first function in the program. B. The function with most lines of code C. The programmer can choose the function D. The main() function
Answer: The main() function
A function may not return a value back A. True B. False
Answer: True
A preprocessor is a software that goes through the C program before compilation A. True B. False
Answer: True
Assignment operator(=) has the lowest precedence than all the arithmetic operators A. True B. False
Answer: True
Evaluate the following logical expression: 7>=6 || 1 < 8 && 7 > 9 A. True B. False
Answer: True
For loop is also known as a continuing loop A. True B. False
Answer: True
If variable a = 4 and b = 5 what will be the output of a < b A. True B. False
Answer: True
If variable a = 4 and b= 5 what will be the output of a < b A. True B. False
Answer: True
In 'C' switch statements are used for making decisions A. True B. False
Answer: True
In C language true is stores as 1 while false is stored as 0 A. True B. False
Answer: True
In a C program, a pointer to the address of a variable A. True B. False
Answer: True
In a C program, true is stored as 1 while false is stored as 0 A. True B. False
Answer: True
Modulus operator (%) can only operate on two whole numbers: A. True B. False
Answer: True
The value of the expression 8 + 12 % 7 is 13 A. True B. False
Answer: True
Variables declared inside a function have a local scope and can only be used inside the function A. True B. False
Answer: True
break; statement is used to end the loop before its normal termination A. True B. False
Answer: True
feof() function is used to detect the end of file A. True B. False
Answer: True
printf is a function in stdio library: A. True B. False
Answer: True
What will be displayed after the following code is executed? int ctr = 1; while (ctr <= 99) { ctr++; } printf("Value of variable ctr is: %d", ctr); A. Value of variable ctr is: 1 B. Value of variable ctr is: 100 C. Value of variable ctr is: 99 D. Value of variable ctr is: 98
Answer: Value of variable ctr is: 100
What will be displayed by the execution of the following code? int a = 20; if(a*2 > 40) { printf("You win!"); }else{ printf("You lose!"); } A. You win! You lose! B. You lose! C. No output D. You win!
Answer: You lose!
Which of the following enters a new line in the output: A. \t B. \\ C. \n D. \*
Answer: \n
Which of the following inserts a new line in the output? A. \t B. \\ C. \* D. \n
Answer: \n
Assume that the goal is to declare a variable to store price of a book. What is the proper data type for this variable? A. struct B. int C. char D. float
Answer: float
Which of the following will determine if num is divisble by 19? Assume that num is initialized to some value. int num = ... A. if (num % 19 == 1) B. if (num / 19 == 0) C. if (num % 19 == 0) D. if (num % 19 = 0)
Answer: if (num % 19 == 0)
Which of the following option is a prototype of the given function? int divide(int a, int b) { return a / b; } A. int divide(int a, int b); B. int divide(int, int); C. void divide(int a, int b); D. int divide();
Answer: int divide(int, int);
Assume we have a struct defined named Record that has int variable count, we declare array of record as follows: Record inventory[20]; Fill in the blank to store count = 10 for every array element in the array inventory int k; for (k=0; k < 20; k++) { -------------------------- } A. count[k]=10; B. inventory.count[k]=10; C. inventory[k].count = 10; D. inventory. count = 10;
Answer: inventory[k].count = 10;
In a C program, the execution begins with which functions? A. Doesn't matter B. There is no function in c program C. main() function D. First function in the program
Answer: main() function
Which statement will store the character K in the variable middle? Assume: char middle; A. middle = 'K'; B. middle = K; C. middle = "K"; D. All of the above
Answer: middle = 'K';
Which statement will assign variable m to n? int m = 12; int n = 7; A. n = m; B. m = n; C. All of the above D. n == m;
Answer: n = m;
Given the following: typedef struct { float radius; float height; } Cylinder; Cylinder object; Which of the following is the right way to assign 12.50 to the height of the variable object A. Cylinder.height = 12.50; B. object.height = 12.50; C. object(height) = 12.50; D. Cylinder.object.height = 12.50;
Answer: object.height = 12.50;
Which of the following is the standard way to print a character variable c; char c = 'c' ; A. printf("%c", c); B. printf("%c", &c); C. printf("%s", c); D. printf("%d", c);
Answer: printf("%c", c);
When you don't want the function to return anything which of the following return type will you use? A. Nothing B. void C. float D. int
Answer: void
Which of the following is the symbol for logical OR? A. || B. ! C. && D. |
Answer: ||