Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++ Function Quiz

Total questions: 10

Worksheet time: 6mins

Name
Class
Date
1.

What is the correct syntax to declare a function that returns an integer in C++?

ايه الطريقة اللي بعرف بيها فانكشن بترجعلي رقم صحيح ؟

a)

int funcName();

b)

void funcName();

c)

float funcName(int x, int y);

d)

double funcName(int x);

2.

What does the keyword return do in a C++ function?

كلمة ريتيرن فايدتها ايه في الفانكشن؟

a)

Terminates the program

b)

Returns control to the operating system

c)

Returns a value from the function

d)

Prints the output of the function

3.

What is the default return type of a C++ function if not specified?

لو انا محددتش نوع الريتين تايب بتاعي اوتوماتيك بيكون ايه

a)

int

b)

void

c)

float

d)

double

4.

Which of the following statements is correct about the scope of variables in C++?

انهي جملة من الجمل اللي ف الاختيارت صح بخصوص الاسكوب في المتغيرات

a)

Global variables can only be used inside the main() function.

b)

Local variables can be used outside the function where they are defined.

c)

Global variables are accessible throughout the entire program.

d)

Variables declared inside a function are accessible from anywhere in the program.

5.

Which built-in function in C++ is used to calculate the square root of a number?

انهي بيلت ان فانشكن مسؤول عن اني اجيب بيه الجذر التربيعي؟

a)

power()

b)

sqrt()

c)

log()

d)

rand()

6.

What happens if you declare two local variables with the same name in two different functions?

هيحصل ايه لو انا عندي اتنين فانكشن مختلفيم مسمي في كل واحدة فيهم متغير بنفس الاسم

a)

Compiler error

b)

The variables share the same value

c)

Each function will have its own version of the variable

d)

The first variable is overwritten by the second one

7.

What is the correct way to call a function named myFunction that takes two integers as arguments?

انهي الطريقة الصح اللي بستدعي بيها الفانكشن اسمها ماي فانكشن بتاخد متغيرين من النوع انتيجر؟

a)

myFunction();

b)

myFunction(a, b);

c)

myFunction(int a, int b);

d)

myFunction(int, int);

8.

Which of the following is a valid function declaration in C++?

انهي فانكشن من اللي ف الاختيارات مكتوبة صح؟ ركز كويس (:

a)

float areaOfCircle(float radius);

b)

int findMax(int x int y);

c)

void swap(int, int)

d)

double multiply();

9.

What is the output of the following code?

int a = 5;

void myFunction() {

int a = 10;

cout << a;

}

int main() {

myFunction();

}

a)

5

b)

10

c)

15

d)

No output, it will cause an error

10.

Which library is required to use the Pow() function in C++?

انهي مكتبة من المكتبات اللي ف الاختيارت بستخدمها عشان خاطر استدعي الفانكشن بتاع الباور او الاس يعني

a)

#include <iostream>

b)

#include <cmath>

c)

#include <cstdlib>

d)

#include <vector>