wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming

Total questions: 60

Worksheet time: 45mins

Name
Class
Date
1.

Trace the following algorithm. What is the final value of Y?


1 Set Y to 0

2 While Y is less than 20

3 Print out the value of Y

4 Increase Y by 2

a)

0

b)

12

c)

20

d)

10

e)

. 22

2.

last stage of problem solving

a)

definition

b)

algorithm

c)

documentation

d)

testing

3.

Which stage of Program Development Process is this?

a)

Defining the problem

b)

Analyzing the problem

c)

Developing an Algorithm

d)

Writing a computer program

4.

The symbol used for getting input and output is

a)

Rectangle

b)

Oval

c)

Parallelogram

d)

Hexagon

5.

What is an algorithm?

a)

A way of describing a problem.

b)

Solving the problem in computer language.

c)

A list of steps that can be followed to solve a problem.

d)

Computers have limitations.

6.

What are the first two stages of the Program Development Process:

a)

Define and Analyze the problem

b)

Analyze the problem and Develop an Algorithm

c)

Define the problem and Test and Debug

d)

Test and Debug and Document the program

7.

What is a variable?

a)

The same as a constant.

b)

A number that is randomly changed.

c)

A piece of information identified by name.

d)

A unknown.

8.

To which stage does this belong?

a)

Analyzing the program

b)

Developing an Algorithm

c)

Writing a computer program

d)

Testing and Debugging

9.
What is the correct definition of an algorithm?
a)
An algorithm is a step by step instructions to solve a problem.
b)
An algorithm is a process of baking bread.
c)
An algorithm is a software used to compute numbers.
d)
An algorithm is the process of breaking problems.
10.
What is a flowchart?
a)
A textual representation of algorithms.
b)
A graphical representation of algorithms.
c)
A cluster of different shapes.
d)
A program code written in Logo.
11.
What does this shape represent in flowchart?
a)
Start/Stop
b)
Decision
c)
Process
d)
Input/Output
12.
The process carried out in computer systems is represented by _______________ in flowchart.
a)
Rectangle
b)
parallelogram 
c)
Square
d)
Diamond
13.
What links each instruction in a flowchart?
a)
A line 
b)
A double line
c)
An arrow
d)
A double arrow
14.

A compiler is

a)

Token

b)

Variable

c)

Translator

d)

Data type

15.
A person who writes code is called a
a)
coder
b)
computer programmer
c)
technologist
d)
scientist
16.

An if statement (i.e. if (condition) { ... }) will only execute if...

a)

The condition is true

b)

The condition is false

c)

It always executes

d)

It never executes

17.

int x=106;

if (x>=60){

cout << "Congrats, you passed";

}

else {

cout << "Check in with me.";

}

}

a)

Congrats, you passed

b)

Check in with me

18.

Follow up: what is the output of this code?

a)

a

b)

b

c)

c

19.

What will be the value of after this set of conditional statements?

a)

7

b)

9

c)

10

d)

4

20.

What will be the output of this code? (hint: the == operator can be used on strings to see if they have the same value, meaning the same exact sequence of characters)

a)

same name

b)

different names

21.
Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and 
"Can get a driver's license" if age is greater than or equal to 16. 
Which of the following code is the best?
a)
if (age < 16) 
 System.out.println("Cannot get a driver's license");
if (age >= 16) 
 System.out.println("Can get a driver's license");
b)
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else 
 System.out.println("Can get a driver's license");
c)
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else if (age >= 16) 
 System.out.println("Can get a driver's license");
d)
if (age < 16) 
 System.out.println("Cannot get a driver's license");
else if (age > 16) 
 System.out.println("Can get a driver's license");
else if (age == 16) 
 System.out.println("Can get a driver's license");
22.

What does the following code fragment write to the monitor?


int sum = 21;

if ( sum == 20 )

{

System.out.print("You win ");

}

else

{

System.out.print("You lose ");

}


System.out.println("the prize.");

a)

You win.

b)

You lose.

c)

You win the prize.

d)

You lose the prize.

23.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

24.

What is the output?

a)

next

stop

b)

next

c)

stop

d)

syntax error - program doesn't work

25.

What is the output?

a)

3

b)

3

7

c)

3

5

7

d)

7

26.

What is the output?

a)

True

b)

NIL

c)

True

NIL

d)

True

NIL

NIL

27.

What is the output?

a)

level 3

b)

level 3

level 1

c)

level 3

level 1

NIL

d)

level 3

level 2

level 1

NIL

28.

What part of an if statement should be indented?

a)

All of it

b)

The statements within it

c)

the first line

d)

the lines within the brackets

29.

What's the name of the variable in this code?

a)

if

b)

print

c)

Weather

d)

weather

30.

What will happen if the answer "rain" is stored in weather?

a)

program will print "take suncream"

b)

Nothing, it's not an option

c)

program will print "take an umbrella"

d)

Don't take an umbrella

31.

A function is a subprogram doing a specific operation on data.

a)

True

b)

False

32.

____ statement in function bring the result to the calling program.

a)

break

b)

return

c)

def

33.

A variable created inside the function has_____ scope.

a)

local

b)

global

34.

What is the return type of a method that does not return any value?

a)

int

b)

float

c)

void

d)

double

35.

The format of function header includes

a)

Function returntype, name, argument list

b)

Function return value, name, argument list

c)

Function return type, name, function body

d)

Function name only

36.

Which one is input function in C

a)

printf()

b)

scanf()

c)

int

d)

%d

37.

syntax of scanf() in C

a)

scanf("format specifier",variable);

b)

scanf("format specifier",&variable);

c)

scanf("format specifier,variable");

d)

scanf(format specifier,&"variable");

38.

syntax of printf() in C

a)

printf("%format specifier",&variable);

b)

printf("%format specifier",variable);

c)

'printf(%format specifier,"variable");

d)

printf("%format specifier,&variable");

39.

format specifier of int

a)

%i

b)

%c

c)

%d

d)

%b

40.

relationl operator in C

a)

*

b)

=

c)

==

d)

?=

41.

Which is output function in C

a)

int

b)

%d

c)

scanf()

d)

printf()

42.

C is a which level language.?

a)

Low Level

b)

High Level

c)

Low + High

d)

none

43.

 

Which of the following true about FILE *fp

a)

FILE is a keyword in C for representing files and fp is a variable of FILE type.

b)

FILE is a stream

c)

FILE is a structure and fp is a pointer to the structure of FILE type

d)

FILE is a buffered stream

44.

#include <stdio.h>

#define MAX(x,y) ((x) > (y) ? (x) : (y))

int main(void)

{

printf("Max between 20 and 10 is %d\n", MAX(10, 20));

return 0;

}

a)

10

b)

error

c)

20

d)

Max between 20 and 10 is 20

45.

What is the file extension of expanded source code of .C file after preprocessing.?

a)

.exe

b)

.c

c)

.i

d)

.p

46.

What does #include<stdio.h> does in c language.?

a)

It includes stdio.h into existing C program.

b)

#include increases the size of C program by including the specified file contents like functions, constants etc.

c)

#include includes specified file before compilation.

d)

All the above

47.

How many members does struct Books contain?

a)

1

b)

0

c)

3

d)

4

48.

A structures are similar to array in that they can store multiple data items.

a)

True

b)

False

49.

A structures are similar to array in that they can store multiple data items.

a)

True

b)

False

50.

Write a line of code giving struct Cars an alternate name.

4 lines
51.

Predict the output of below program:

int main()

{

    int arr[5];

     

    // Assume that base address of arr is 2000 and size of integer

        // is 32 bit

    arr++;

    printf("%u", arr);

     

    return 0;

}

a)

2002

b)

2004

c)

2020

d)

lvalue required

52.

Predict the output of below program:

#include <stdio.h>

 

int main()

{

    int arr[5];

    // Assume base address of arr is 2000 and size of integer is 32 bit

    printf("%u %u", arr + 1, &arr + 1);

 

    return 0;

}

a)

2004 2020

b)

2004 2004

c)

2004 Garbage value

d)

The program fails to compile because Address-of operator cannot be used with array name

53.

What is output?

# include <stdio.h>

 

void print(int arr[])

{

   int n = sizeof(arr)/sizeof(arr[0]);

   int i;

   for (i = 0; i < n; i++)

      printf("%d ", arr[i]);

}

 

int main()

{

   int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};

   print(arr);

   return 0;

}

a)

1, 2, 3, 4, 5, 6, 7, 8

b)

Compiler Error

c)

1 2

d)

Run Time Error

54.

Output of following program?

#include<stdio.h>

   

int main()

{

  int a[] = {1, 2, 3, 4, 5, 6};

  int ptr = (int)(&a+1);

  printf("%d ", *(ptr-1) );

  return 0;

}

a)

1

b)

2

c)

6

d)

Runtime Error

55.

Which of the following is true about arrays in C.

a)

For every type T, there can be an array of T.

b)

When an array is passed to a function, C compiler creates a copy of array.

c)

For every type T except void and function type, there can be an array of T.

d)

2D arrays are stored in column major form

56.

Predict the output of the below program:

#include <stdio.h>

#define SIZE(arr) sizeof(arr) / sizeof(*arr);

void fun(int* arr, int n)

{

    int i;

    arr += (arr + n - 1) += 10;

}

 

void printArr(int* arr, int n)

{

    int i;

    for(i = 0; i < n; ++i)

        printf("%d ", arr[i]);

}

 

int main()

{

    int arr[] = {10, 20, 30};

    int size = SIZE(arr);

    fun(arr, size);

    printArr(arr, size);

    return 0;

}

a)

20 20 40

b)

20 30 40

c)

50 20 40

d)

Compile-time error

57.

Predict output of following program.

int main()

{

    int i;

    int arr[5] = {1};

    for (i = 0; i < 5; i++)

        printf("%d ", arr[i]);

    return 0;

}

a)

1 1 1 1 1

b)

1 followed by four garbage values

c)

1 0 0 0 0

d)

0 0 0 0 0

58.

#include <stdio.h>

 

int main()

{

    int a[][] = {{1,2},{3,4}};

    int i, j;

    for (i = 0; i < 2; i++)

        for (j = 0; j < 2; j++)

            printf("%d ", a[i][j]);

    return 0;

}

a)

4 3 2 1

b)

Compiler Error in line " int a[][] = {{1,2},{3,4}};"

c)

1 2 3 4

d)

4 garbage values

59.

#include<stdio.h>

int main()

{

    int a[10][20][30] = {0};

    a[5][2][1] = 2;

    return 0;

}

Which of the following will print the value 2 for the above code?

a)

printf("%d",*(*(*(a+5)+2)+1));

b)

printf("%d",***((a+5)+2)+1);

c)

printf("%d",*(((a+5)+2)+1));

d)

None of these

60.

What does <= mean?

a)

less than

b)

greater than

c)

less than or equal to

d)

greater than or equal to