Font size
WorksheetsProgramming
Total questions: 60
Worksheet time: 45mins
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
0
12
20
10
. 22
last stage of problem solving
definition
algorithm
documentation
testing
Which stage of Program Development Process is this?
Defining the problem
Analyzing the problem
Developing an Algorithm
Writing a computer program
The symbol used for getting input and output is
Rectangle
Oval
Parallelogram
Hexagon
What is an algorithm?
A way of describing a problem.
Solving the problem in computer language.
A list of steps that can be followed to solve a problem.
Computers have limitations.
What are the first two stages of the Program Development Process:
Define and Analyze the problem
Analyze the problem and Develop an Algorithm
Define the problem and Test and Debug
Test and Debug and Document the program
What is a variable?
The same as a constant.
A number that is randomly changed.
A piece of information identified by name.
A unknown.
To which stage does this belong?
Analyzing the program
Developing an Algorithm
Writing a computer program
Testing and Debugging
A compiler is
Token
Variable
Translator
Data type
An if statement (i.e. if (condition) { ... }) will only execute if...
The condition is true
The condition is false
It always executes
It never executes
int x=106;
if (x>=60){
cout << "Congrats, you passed";
}
else {
cout << "Check in with me.";
}
}
Congrats, you passed
Check in with me
Follow up: what is the output of this code?
a
b
c
What will be the value of after this set of conditional statements?
7
9
10
4
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)
same name
different names
"Can get a driver's license" if age is greater than or equal to 16.
Which of the following code is the best?
System.out.println("Cannot get a driver's license");
if (age >= 16)
System.out.println("Can get a driver's license");
System.out.println("Cannot get a driver's license");
else
System.out.println("Can get a driver's license");
System.out.println("Cannot get a driver's license");
else if (age >= 16)
System.out.println("Can get a driver's license");
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");
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.");
You win.
You lose.
You win the prize.
You lose the prize.
What is the output?
more than 7
more than 23
spam
7
What is the output?
next
stop
next
stop
syntax error - program doesn't work
What is the output?
3
3
7
3
5
7
7
What is the output?
True
NIL
True
NIL
True
NIL
NIL
What is the output?
level 3
level 3
level 1
level 3
level 1
NIL
level 3
level 2
level 1
NIL
What part of an if statement should be indented?
All of it
The statements within it
the first line
the lines within the brackets
What's the name of the variable in this code?
if
Weather
weather
What will happen if the answer "rain" is stored in weather?
program will print "take suncream"
Nothing, it's not an option
program will print "take an umbrella"
Don't take an umbrella
A function is a subprogram doing a specific operation on data.
True
False
____ statement in function bring the result to the calling program.
break
return
def
A variable created inside the function has_____ scope.
local
global
What is the return type of a method that does not return any value?
int
float
void
double
The format of function header includes
Function returntype, name, argument list
Function return value, name, argument list
Function return type, name, function body
Function name only
Which one is input function in C
printf()
scanf()
int
%d
syntax of scanf() in C
scanf("format specifier",variable);
scanf("format specifier",&variable);
scanf("format specifier,variable");
scanf(format specifier,&"variable");
syntax of printf() in C
printf("%format specifier",&variable);
printf("%format specifier",variable);
'printf(%format specifier,"variable");
printf("%format specifier,&variable");
format specifier of int
%i
%c
%d
%b
relationl operator in C
*
=
==
?=
Which is output function in C
int
%d
scanf()
printf()
C is a which level language.?
Low Level
High Level
Low + High
none
Which of the following true about FILE *fp
FILE is a keyword in C for representing files and fp is a variable of FILE type.
FILE is a stream
FILE is a structure and fp is a pointer to the structure of FILE type
FILE is a buffered stream
#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;
}
10
error
20
Max between 20 and 10 is 20
What is the file extension of expanded source code of .C file after preprocessing.?
.exe
.c
.i
.p
What does #include<stdio.h> does in c language.?
It includes stdio.h into existing C program.
#include increases the size of C program by including the specified file contents like functions, constants etc.
#include includes specified file before compilation.
All the above
How many members does struct Books contain?
1
0
3
4
A structures are similar to array in that they can store multiple data items.
True
False
A structures are similar to array in that they can store multiple data items.
True
False
Write a line of code giving struct Cars an alternate name.
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;
}
2002
2004
2020
lvalue required
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;
}
2004 2020
2004 2004
2004 Garbage value
The program fails to compile because Address-of operator cannot be used with array name
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;
}
1, 2, 3, 4, 5, 6, 7, 8
Compiler Error
1 2
Run Time Error
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;
}
1
2
6
Runtime Error
Which of the following is true about arrays in C.
For every type T, there can be an array of T.
When an array is passed to a function, C compiler creates a copy of array.
For every type T except void and function type, there can be an array of T.
2D arrays are stored in column major form
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;
}
20 20 40
20 30 40
50 20 40
Compile-time error
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;
}
1 1 1 1 1
1 followed by four garbage values
1 0 0 0 0
0 0 0 0 0
#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;
}
4 3 2 1
Compiler Error in line " int a[][] = {{1,2},{3,4}};"
1 2 3 4
4 garbage values
#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?
printf("%d",*(*(*(a+5)+2)+1));
printf("%d",***((a+5)+2)+1);
printf("%d",*(((a+5)+2)+1));
None of these
What does <= mean?
less than
greater than
less than or equal to
greater than or equal to
