0% found this document useful (0 votes)
7 views10 pages

ICT Unit-6 Worksheet 3rd Round C++

The document is an ICT worksheet for Grade 9 students at Ambo IFA Boru Special Boarding Secondary School, focusing on programming with C++. It includes a series of true/false statements and multiple-choice questions related to C++ programming concepts. The worksheet is prepared by teacher Diro Bayisa Meka and contains a total of 135 questions.

Uploaded by

diro bayisa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

ICT Unit-6 Worksheet 3rd Round C++

The document is an ICT worksheet for Grade 9 students at Ambo IFA Boru Special Boarding Secondary School, focusing on programming with C++. It includes a series of true/false statements and multiple-choice questions related to C++ programming concepts. The worksheet is prepared by teacher Diro Bayisa Meka and contains a total of 135 questions.

Uploaded by

diro bayisa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

AMBO IFA BORU SPECIAL BOARDING SECONDARY SCHOOL IN 2017/2025

ICT Work Sheet for Grade 9 Based on Table of Specification in 2017 E.C

Total questions [135]

Teacher’s Name: Diro Bayisa Meka Signature: Date: 13/8/2017

Dep’t Head: _____________ Signature: ________Date:________

A/Vice Principal: _____________ Signature: _____Date: ___

ICT ANSWER KEY


AIBSBSS
ICT 3rd ROUND WORKSHEET CHAPTER-6 PROGRAMMING WITH C++ FOR GRADE 9TH

I. Write “True” if the following statement is/ are correct otherwise “False”
1.In C++, a variable can be declared without initializing it, and it will automatically have a default value. False
2.The name of a variable in C++ must start with a letter or an underscore. True

3.In C++, variables of different types can be declared in the same statement, separated by commas. True
4.A variable in C++ can be assigned a value after it has been declared, but only once. False

5.C++ identifiers are case-sensitive, meaning variable, Variable, and VARIABLE are treated as different
identifiers. True
6.A variable declared inside a function is accessible outside of that function. False
7.Global variables are accessible throughout the entire program, including inside functions. True
8.In C++, the int data type can hold both integer values and floating-point numbers. False
9.The char data type in C++ is used to store single characters, but it is stored as an integer internally. True
10.A function can be called before it is defined, as long as there is a function prototype (declaration) above
the call. True
11.In C++, you can have multiple functions with the same name if they have different return types. True
12.The if statement in C++ can only evaluate conditions that result in a boolean value. True
13.The continue statement in a loop causes the program to exit the loop and proceed with the next iteration. True
14.The index of the first element in an array in C++ is always 1. False
15.A pointer can be used to store the address of a constant variable, but it cannot modify the value of the
variable it points to. False

II. Choose the correct answer for the following questions


1.Where can a local variable be accessed?
A. Anywhere in the program B. Only inside the function or block where it is declared
C. Inside any function D. Only in the main function
2. What will the following code print?
int x = 5;
void show() {
int x = 10;
cout << x;}
A. 5 B. 10 C. Error: x redeclared D. Nothing
3. What is the scope of a variable declared inside a loop?
for (int i = 0; i < 5; i++) {
cout << i;
} A. Global B. Function C. Loop block D. Class
4. Which of the following variables have global scope?
int g = 100;
int main() {
ICT-G-9 | Prepared by: DiroB.
AIBSBSS
int x = 10;
}
A. g only B. x only C. Both g and x D. Neither
5. What will this code print?
int x = 20;
int main() {
int x = 10;
cout << x;
} A. 20 B. 10 C. Error D. Nothing
6. What is the output?
void show() {
int a = 5;
{
int a = 10;
cout << a;
}
cout << a;
} A. 10 5 B. 5 10 C. 10 10 D. Error
7. Which output is correct?
int a = 1;
int main() {
int a = a + 1;
cout << a;
} A. 2 B. 1 C. Undefined behavior D. Error
8.What is the scope of a variable declared inside a function in C++?
A. Global B. File C. Local D. Block
9.What will happen if a local variable has the same name as a global variable?
A. Compiler error B. Global variable is overridden permanently
C. Local variable will shadow the global variable D. Both will be accessible
10.Which type of variable is accessible throughout the program, across all functions and files (if declared
properly)? A. Static variable B. Local variable C. Global variable D. Auto variable
11.Which of the following is a valid variable name in C++?
A. 2ndPlace B. float C. _myVar D. @score
12.Which of the following cannot be used in variable names?
A. Underscore _ B. Digits after the first character
C. Uppercase letters D. Reserved keywords
13.What is the result of the expression 5 % 2? A. 2 B. 0 C. 1 D. 5
14.Which of the following is a logical operator in C++? A. & B. && C. | D. ^
15.What will the result of true || false be? A. true B. false C. 0 D. 1
16.Which of the following is the bitwise NOT operator? A. ~ B. ! C. ^ D. &
17.What type of operator is ++ in C++? A. Logical B. Arithmetic C. Increment D. Relational
18.Which operator is used for scope resolution in C++? A. :: B. . C. -> D. #

ICT-G-9 | Prepared by: DiroB.


AIBSBSS
19.Which of the following is a correct variable declaration in C++?
A. int 1var; B. float my value; C. char_name = 'A'; D. double salary;
20.Which of the following data types is used to store true/false values?
A. char B. int C. bool D. float
21.Which of the following can be used to define a global variable?
A. Inside a function B. Inside an if block C. Outside all functions and classes D. Inside a switch case
22.Which type specifier is used to declare floating-point numbers? A. bool B. char C. int D. float
23.Which statement about variables in C++ is true?
A. A variable must be declared after it is used
B. A variable name can include spaces
C. A variable can only store one value at a time
D. You can use int to store characters
24.What is the size of the char data type in C++? A. 8 bits B. 16 bits C. 32 bits D. 64 bits
25.Which of the following is used to store a single character? A. string B. char C. bool D. float
26.What does the bool data type store? A. Strings B. Numbers C. Decimal values D. True or false
28.What is the main purpose of #include <iostream> in a C++ program?
A. To handle file input/output B. To perform mathematical operations
C. To use cin and cout D. To define variables
29.Which of the following is defined in <iostream>? A. printf B. scanf C. cin D. malloc
30.What kind of file is <iostream>? A. Source file B. Executable C. Header file D. Object file
31.Which C++ standard library namespace must be used to access cin and cout directly?
A. stdlib B. input C. io D.std
32.Which operator is used with cout for output? A. >> B. << C. ** D. ->
33.What does the #include directive do?
A. Runs the program B. Imports a class C. Replaces code with the contents of a file D. Compiles the file
34.Which of the following statements will correctly print "Hello" to the console?
A. cout << Hello; B. cout >> "Hello"; C. std::cout << "Hello"; D. echo("Hello");
35.Which of the following keywords is needed to avoid writing std:: before cin and cout?
A. using iostream; B. namespace std; C. include std; D. using namespace std;
36.Who developed the C++ programming language?
A. Dennis Ritchie B. Bjarne Stroustrup C. James Gosling D. Guido van Rossum
37.What does C++ primarily add to the C programming language?
A. Better file handling B.GUI support C. Object-oriented features D. More keywords
38.Which file extension is commonly used for C++ source files? A. .c B. .cp C. .cpp D..ccp
39.Which of the following is not a feature of C++?
A. Encapsulation B. Inheritance C. Garbage collection D. Operator overloading

ICT-G-9 | Prepared by: DiroB.


AIBSBSS
40.Which of the following is a valid main function in C++?
A. int main[] B. main() C. int main() D. void main()
41.Which of the following is a correct way to start a comment in C++?
A. /** B. \\ C. /* D. //
42.Which C++ feature allows functions with the same name but different parameters?
A. Inheritance B. Overloading C. Encapsulation D. Polymorphism
43.What is the primary purpose of a namespace in C++?
A. To define data types B. To resolve function overloading
C. To prevent name conflicts D. To allocate memory dynamically

44.Which standard namespace is most commonly used in C++? A. io B. system C. main D. std
45.What does the statement using namespace std; do?
A. Imports a class from a library B. Defines a new namespace
C. Tells the compiler to use the std namespace D. Compiles the program
46.What happens if two functions have the same name but are in different namespaces?
A. Compilation error B. The second one overrides the first
C. Runtime warning D. No conflict — namespaces isolate them
47.Which keyword is used to access a specific item from a namespace without using using namespace?
A. from B. with C. namespace D. ::
48.What happens when the compiler encounters a comment in C++ code?
A. It executes the comment B. It raises a syntax error
C. It treats it as code D. It ignores the comment
49.Why are comments used in C++ code? A. To slow down execution B. To make code unreadable
C. To store runtime values D. To describe or explain code
50.Which of the following is a valid comment in C++?
A. # This is a comment B. <!-- This is a comment --> C. // This is a comment D. 'This is a comment'
51.What does the following statement do?
float rate = 4.5;
A. Declares a string variable B. Declares a float variable and assigns it 4.5
C. Declares an integer and initializes it D. Assigns 4.5 to an undeclared variable
52.Which of the following is not a valid variable name in C++?
A. _value B. total1 C. 3score D. value_3
53.Which of the following correctly initializes multiple variables of the same type?
A. int a, b = 5, c = 10; B. int a = b = c = 10; C. int a b c = 5; D. int a == 5, b == 6;
54.Which of the following is a valid string variable declaration in C++?
A. string name = "John"; B. String name = John; C. text name = "John"; D. char name = "John";
55.Which of the following is the correct syntax for taking input from the user in C++?
A. cin >> variable; B. input variable; C. scanf(variable); D. read variable;
56.What is the header file required to use cin and cout in C++?
A. #include <stdio.h> B. #include <input.h> C. #include <iostream> D. #include <cinout.h>>

ICT-G-9 | Prepared by: DiroB.


AIBSBSS
56.Which of the following is the correct syntax for an if statement in C++?
A. if (x = 10) {} B. if x == 10 {} C. if (x == 10) {} D. if x = 10 then {}
57.What is the purpose of the else statement in C++?
A. To handle an exception B. To execute a block of code if the if condition is false
C. To repeat a block of code D. To skip the current iteration of a loop
58.What does the break statement do inside a loop in C++?
A. Exits the current loop and transfers control to the next iteration
B. Skips the current iteration and goes to the next
C. Exits the loop entirely and moves on to the code after the loop
D. Stops the program execution
59.Which of the following C++ loops will execute at least once even if the condition is false?
A. for loop B. while loop C. do-while loop D. foreach loop
60.What is the correct syntax for a switch statement in C++?
A. switch (x) { case 1: // code; break; } B. switch { x case 1: // code; break; }
C. case (1) switch: // code; break; D. if case (1): switch { // code; break; }
61.Which of the following is the correct way to write a for loop that prints numbers from 1 to 5?
A. for (int i = 1; i <= 5; i++) { cout << i; } B. for (int i = 1; i < 5; i--) { cout << i; }
C. for (int i = 0; i <= 5; i++) { cout << i; } D. for (int i = 5; i > 0; i--) { cout << i; }
62.Which C++ statement is used to skip the current iteration of a loop?
A. stop B. continue C. skip D. exit
63.What is the result of the following code snippet?
int x = 5;
if (x > 10) {
cout << "Greater";
} else {
cout << "Smaller";
} A. Greater B. Smaller C. No output D. Compilation error
64.What is the correct syntax for declaring an array of 5 integers in C++?
A. int arr[5]; B. array int arr[5]; C. int arr(5); D. int[] arr = 5;
65.What will be the output of the following code?
int arr[3] = {1, 2, 3};
cout << arr[1]; A. 1 B. 2 C. 3 D. Compilation error
66.Which of the following is the correct way to initialize an array of size 4 with all elements set to zero?
A. int arr[4] = {}; B. int arr[4] = {0}; C. int arr[4] = {0, 0, 0, 0}; D. All of the above
67.Which of the following is the correct way to pass an array to a function in C++?
A. function(arr[]); B. function(arr); C. function(int arr[]); D. All of the above
68.Which of the following is true about the size of an array in C++?
A. The size of the array must be known at compile time
B. The size of the array can be changed after initialization
C. The size is automatically calculated by the compiler for dynamic arrays
D. The size is fixed but can be determined using sizeof only at runtime
69.Which of the following is the correct way to declare a function in C++?

ICT-G-9 | Prepared by: DiroB.


AIBSBSS
A. function int myFunction(); B. void myFunction(int x);
C. int function myFunction(int x); D. myFunction(int x);
70.Which of the following correctly defines a function that returns an integer and takes two integer
parameters in C++?
A. int sum(int a, int b) { return a + b; } B. int sum(a, b) { return a + b; }
C. sum(int a, int b) { return a + b; } D. int sum(int a, int b): return a + b;
71.Which of the following is the correct way to call the function int add(int, int) in C++?
A. add(5, 10); B. add(5, 10) C. call add(5, 10); D. add int(5, 10);
72.What is the purpose of the return statement in a function?
A. It terminates the program B. It ends the execution of the function and optionally returns a value
C. It calls another function D. It pauses the program
73.Which of the following is true about default arguments in C++ functions?
A. Default arguments can only be specified for the first parameter
B. Default arguments must be specified for every parameter
C. Default arguments are given values when the function is called without those arguments
D. Default arguments cannot be used in functions that return values
74.What will happen if a function is called without arguments, but the function is declared with required
arguments in C++?
A. The function will execute normally B. The program will compile but throw a runtime error
C. The program will not compile due to incorrect arguments D. The function will be skipped
75.Which of the following statements is true about function overloading in C++?
A. Function overloading occurs when multiple functions have the same name but different return types
B. Function overloading is only possible if the functions have different parameter types
C. Function overloading allows multiple functions with the same name but different numbers or types of
parameters D. Function overloading is not supported in C++
76.What is a recursive function in C++?
A. A function that calls itself directly or indirectly B. A function that takes multiple arguments
C. A function that always returns the same value D. A function that handles exception errors
77.What is a function prototype in C++?
A. The function's definition that includes its body
B. A declaration of the function that tells the compiler its return type and parameters
C. A function that does not return a value
D. A function that is defined inside another function
78.Which of the following is the correct syntax for a function prototype in C++?
A. int add(int, int); B. int add(int x, int y) { return x + y; }
C. int add(int x, int y) D. int add(int, int) { return x + y; }
79.What is the purpose of a function prototype in C++?
A. To define the function's implementation
B. To specify the function's return type and parameter types before its definition
C. To optimize the function during compilation
D. To call the function before its definition
80.Which of the following is not required in a function prototype?
A. Function name B. Return type C. Parameter names D. Parameter types

ICT-G-9 | Prepared by: DiroB.


AIBSBSS
81.Which of the following statements about function prototypes is true?
A. A function prototype must always be placed after the function definition
B. A function prototype is not needed if the function definition appears before its usage
C. Function prototypes are not used in C++
D. A function prototype can only be used for functions with no parameters
82Which of the following is a function that does not return a value in C++?
A. int functionName(); B. void functionName(); C. char functionName(); D. float functionName();
83.Which of the following describes a recursive function in C++?
A. A function that is always called with the same arguments B. A function that calls another function
C. A function that calls itself either directly or indirectly D. A function that has no return type
84.What is the purpose of an inline function in C++?
A. To speed up the program by directly inserting the function code into the calling code
B. To prevent recursion
C. To define functions that can be called from anywhere
D. To define functions that do not require parameters
85.Which of the following is true about parameters in a C++ function?
A. Parameters are values passed to the function when it is called
B. Parameters are declared inside the function's body
C. Parameters must always be passed by reference
D. Parameters are always optional and can be skipped in function calls
86.What type of parameter passing allows changes to the argument in the calling function?
A. Pass by value B. Pass by reference C. Pass by pointer D. Pass by address
87.Which of the following correctly defines a function that takes two parameters and returns their sum?
A. int add(int a, int b) { return a + b; }
B. add(int a, int b) { return a + b; }
C. int add(a, b) { return a + b; }
D. int add(int a, int b)
88.What is the key difference between pass-by-value and pass-by-reference in C++?
A. Pass-by-value passes the memory address of the variable, while pass-by-reference passes the actual value.
B. Pass-by-value allows the function to modify the argument, while pass-by-reference does not.
C. Pass-by-value makes a copy of the argument, while pass-by-reference passes the original variable.
D. Pass-by-value is used for functions that do not return anything, while pass-by-reference is for functions
that return a value.
89.Which of the following defines a function with default parameters?
A. int add(int x, int y = 10) { return x + y; } B. int add(x, y) { return x + y; }
C. int add(int x, int y) { return x + y; } D. int add(int, int = 10) { return x + y; }
90.What is function overloading in C++?
A. A function that takes a fixed number of arguments
B. A function that can have multiple definitions with the same name but different return types
C. A function that is called recursively
D. A function that has the same name but different parameter types or numbers of parameters
91.Which of the following is an example of function overloading?
A.
int add(int a, int b) { return a + b; }

ICT-G-9 | Prepared by: DiroB.


AIBSBSS
double add(double a, double b) { return a + b; }
B.
int add(int a, int b) { return a + b; }
void add() { cout << "No parameters"; }
C.
int add(int a, int b) { return a + b; }
int add(int a, double b) { return a + b; }
D.
int add(int a, int b) { return a + b; }
int add(int a, int b) const { return a + b; }
92.What will happen if you try to overload two functions in C++ with the same name and identical parameter
types, but different return types?
A. The compiler will allow the overloading based on return type
B. The program will compile, but it will throw a runtime error
C. The compiler will generate an error because it cannot distinguish between the two functions
D. The program will fail silently without any error
93.What will be the output of the following code?
void display(int a, int b) {
cout << a << " " << b;
}

int main() {
int x = 5, y = 10;
display(x, y);
return 0;
}
A. 10 5 B. 5 10 C. 5 5 D. Compilation error
94.What does a pointer in C++ store?
A. A variable's value B. The address of another variable
C. A constant value D. The return type of a function
95.What is the purpose of the dereference operator (*) in C++?
A. To declare a pointer B. To access the memory address of a variable
C. To access the value stored at the memory address a pointer is pointing to D. To assign a value to a pointer
96.Which of the following is the correct syntax to declare a pointer to an integer in C++?
A. int* ptr; B. pointer int* ptr; C. int ptr*; D. int &ptr; E. pointer int ptr;
97.What is the output of the following code?
int num = 10;
int* ptr = &num;
cout << *ptr; A. 10 B. The memory address of num C. Undefined behavior D. 0
98.What is the purpose of the & operator when used with a variable in C++?
A. To get the address of the variable B. To dereference the pointer
C. To define a pointer D. To assign a pointer to a variable
99.Which of the following is an example of a pointer to a pointer in C++?
A. int* ptr = &num; B. int** ptr = &ptr1; C. int* ptr = &ptr1; D. int* ptr = *num;
100.Which of the following correctly initializes a pointer to a constant integer?
A. const int* ptr = &num; B. int* const ptr = &num; C. int* ptr = &num; D. const int ptr = &num;

ICT-G-9 | Prepared by: DiroB.


AIBSBSS
III. Determine the output of the following C++ Programs
#include<iostream>
using namespace std;
int x=10; // here x is global variable
int main(){
int x=20; // x is local variable

int y=30; //y is local variable


20
cout<<x<<endl; //1_____________
cout<<++x<<endl; 21
//2_____________
21
cout<<x<<endl; //3_____________
cout<<x++<<endl; 21
//4_____________
cout<<--x<<endl; 21
//5_____________
21
cout<<x--<<endl; //6_____________
cout<<x<<endl; 20
//7_____________
cout<<x/y<<endl; //8_____________
0

cout<<y/x<<endl; 1
//9_____________
0
cout<<x%2<<endl; //10_____________
cout<< ((x>y) && (x<y)) <<endl; 0
//11_____________
0
cout<<((x<y) && (x>y)) <<endl; //12_____________
cout<<((x>y) || (x<y)) <<endl; 1
//13_____________
1
cout<<((x<y) || (x>y)) <<endl; //14_____________
4 10100 & 00110=00100=4
cout<< 20 & 6 <<endl; //15_____________
22
cout<<20 | 6<<endl; //16_____________ 10100 | 00110=11010=22
18 10100 ^ 00110=10010=18
cout<<20 ^ 6<<endl; //17_____________
cout<<~ 3<<endl; -4
//18_____________ 011=011+1=100= -4

cout<<20<<3<<endl; 160 20*2pow3=20*8=160


//19_____________
2 20/2pow3=20/8=2.5=2
cout<<20>>3<<endl; //20_____________
}

ICT-G-9 | Prepared by: DiroB.

You might also like