Computer Short Questions
Computer Short Questions
Long Question: -
1) Explain Rules of naming variables in C Language.
2) Explain operator and it’s types in C Language.
Chapter # 10 Important Short Questions
1) What is printf function?
Printf() function is used to display text messages and values of variables on monitor screen in a specific
format. It is also called formatted output function. Syntax is printf(“Format String”,Argument List);
2) What is format string?
It is also called control string. It is written in between double quotation marks. It may contain text, format
specifier and escape sequence.
3) What is format specifier?
It represents the format in which value of variable is displayed. It starts with % sign. Example %d, %c, %f.
4) What is Escape Sequence?
It controls the position of output displayed on the screen. Example \n, \t.
5) What is field width specifier?
Field width specifier is a numeric code or rule that specifies the minimum number of columns used to
print a value. It determines the space occupied by a value of the output screen. It is written in printf or
scanf statements between % and f. Example %4d if value is 22 then out put will be ||22.
6) What is the use of scanf () function. Write it’s syntax Or Define Scanf()?
Scanf is used to get input from the user. The input is stored in a variable in a specified form.
Syntax (“format string”, & variable1, & variable 2)
7) What is the use of ampersand (&) sign in scanf function?
The ampersand & refers to the memory location of the variable in which the input is stored. It is placed
before the variable name. It is also called address operator.
8) What will be the output of the following
Printf(“55\t”);
Printf(“555”);
Out put will be 55 555
9) Describe clrscr() function.
This function is used to clear the output screen console.
10) How getch() is different from getche() function?
getch() getche()
This function is used to input single character from user. This function is used to input single character from user.
It is an abbreviation of get character. When user enter a It is an abbreviation of get character with echo. When
character that character is not displayed on screen. user enter a character that character is not displayed on
screen.
11) Define Standard output.
This term refers to the output displayed on monitor. The result of program is standard output of program.
12) List some important function for input.
(1) scanf (2) gets() (3) getch() (4) getche()
13) List out different types of format specifier?
(1) Integer format specifier %d or %i (2) Character format specifier %c (3) Floating point format specifier %f
14) List down the names of escape character provided by c?
(1) \n insert new line (2) \t used to insert multiple space (3) \b generate effect of backspace (4)\’ insert single quote.
15) What is standard input?
Instructions or input provided by the keyboard to computer is called standard input, scanf() function is used to take
standard input from user.
Some Important Programs to practice are here as under
Chapter # 11 Important Short Questions
1) Define control structure.
Control structure is a structure which is used to control the flow of execution of the program. The basic
control structure for writing programs are sequence, selection and repetition.
2) Define sequential structure? OR How instructions are executed in sequence structure?
In sequence structure, the instructions are executed in the same order in which they are specified in the
program. The control flows from one statement to other in a logical sequence.
3) What is your understanding about compound statement?
Compound statement refers to a group of statements inclosed in opening and closing braces such as
{
Statement 1;
Statement 2;
Statement 3;
}
4) Define selection structure?
Selection structure selects a statement or set of statements to execute on the basis of a condition. There
are two types of selection structure 1) if – else 2) switch
5) What do you know about if statement? Also Write syntax.
If is a keyword in c language. If statement is a decision making statement. It is used to execute or skip
statement or set of statement by checking a condition.
Syntax: - if (condition)
{
Statements;
}
6) What is the use of if – else statement?
If – else statement can be used to choose one block of statements from many blocks of statements. It is
used when there is many options and only one block of statements should be executed on the basis of a
condition.
Syntax : - if (condition)
{
Statements;
}
else
{
Statements;
}
7) Where did we use if – else if statement.
Nested if statemetns can become complex. If there are more than three alternatives and indentation is
not consistent then if statement with multiple alternative if – else if can be a good option. Syntax is
if(condition1)
Statements;
else if (contition2)
else
Statement;
8) What is nested if statement?
It means if statement inside another if statement. Nesting can be done up to any level. Use of nesting will
increase complexity of program.
9) How would you compare nested if with sequence of ifs.
In case of nested if statement, when the control flow reaches a logical decision, the rest of the conditions
are skipped. Whereas in a sequence of if statements, all conditions are tested in any case.
10) What is switch structure? Also write syntax.
Switch statement is another conditional structure. It is good alternative of nested if – else if statements
can be used easily when there are many choices available and only one should be executed.
Syntax: - switch(expression)
{
case val1:
statement;
break;
case val2:
statement;
break;
default:
statements;
break;
}
11) What happens if break is missed in case of blocks?
If break is not used, all case blocks coming after matching case will also be executed. Which will take more
time to execute a program.
12) Why a default label is used in switch statement?
The default label appears at the end of the all case labels. It executed only when the result of expression does not
match with any case label. Its use is optional. The position of default label is not fixed.
13) Define conditional operator? Write its syntax.
Conditional operator is decision making structure. It can be used in place of simple if – else structure. It is also called
ternary operator as it uses three operands.
Syntax: - (conditional expression)? True - case statement: false – case statement;
14) Convert this statement with conditional operator to an equivalent if – else statement. Amount=(x>y)? x*y : x+y;
if(x>y)
amount = x*y;
else
amount = x+y;
15) What is compound condition statement?
A statement in which more than one condition is evaluated is called compound condition operator. It is used to
execute a statement or set of statements by testing many conditions.
Long Questions
1) Write a program that inputs a character and determines whether it is a vowel or not.
2) Write a program in C-Language that inputs a number and finds out whether it is even or odd number.
3) Write a program in C-Language to accept a year from the keyboard. Find out it is a Leap Year Or Not.
4) Write a program in C that inputs the number of the month of the year and display the number of days of the
corresponding month using if – else – if statement. e.g. if user enters 2, it will display 28 of 29.
Chapter # 12 Important Short Questions
1) Define Loop and write names of different types of loop in C.
A structure that would allow repeating a set of statements up to fixed number of times or until a certain
criteria is satisified. There are three types of loops available in C. 1-while Loop.2. Do-while loop 3. For loop
2) Define while loop and write syntax for single and multiple statement.
While loop keep repeating statements until the specified condition becomes false. This is useful where
the programmer does not know how many time the loop will be executed. Syntax of while loop single
statement is.
while(condition)
Statements;
Syntax of while loop for multiple statements.
while(condition)
{
Statement1;
Statement2;
Statement 3;
}
3) What do you mean by loop control variable?
A variable whose value controls the number of iterations is known as loop control variable. In while loop,
loop control variable is always initialized outside the body of the loop and increment and decremented
inside body of loop.
4) Define do while loop and explain where or why we use do while loop?
The do-while loop is an iterative control in C Language. It executes one or more statements while the
given condition is true. In this loop the condition comes after the body of loop. This loop is used in a
situation where a statement must be executed at least once.
Syntax : -
do
{
Statements;
}while(condition);
5) Define go to statement?
The go to statement is used to perform an unconditional transfer of control to a named label. The label
must be in thee same function. A label is meaningful only to a go to statement. The general form of to to
statement is a s follows
goto label;
label:
6) What is for loop? Write its syntax with example.
For loop executes one or more statements for a specified number of times. This loop is also called counter
controlled loop. It is the most flexible loop. All the contents are written in a single line in this loop. That is
why most programmers use it in programs.
Syntax: -
For(initialization; condition; increment/decrement)
{
Statements;
}
7) Differentiate between counter and conditional loop.
Counter Loop Conditional Loop
In counter loop, statements are executed to a fix In conditional loop statements execution depends
number of a value. That value is known as counter upon a specific condition. Suppose a loop will
value. Suppose a statement is executed for 5 times. terminate if user enters -1.
5 is counter value.
8) Define sentinel control loop.
A type of loop in which execution of loop is depends on the sentinel value. His type of loop depends on
special value known as sentinel value. Sentinel value indicates that the loop should continue or not. For
example loop execute if value of a variable is not -1. Here -1 is a sentinel value that is used to terminate
loop.
9) Why sentinel value is used in loop?
A type of loop in which execution of loop is depends on the sentinel value. His type of loop depends on
special value known as sentinel value. Sentinel value indicates that the loop should continue or not. For
example loop execute if value of a variable is not -1. Here -1 is a sentinel value that is used to terminate
loop.
10) Define nested loop.
A loop within a loop is called nested loop. In nested loops the inner loop is executed completely with each
change in the value of counter variable of outer loop.
11) What is continue statement?
Continue statement is used to move the control to the beginning of loop until condition is true.
12) Define post test loop.
A type of loop in which condition is checked after the executing the body of the loop. It means that the
statement in the loop will be executed at least once.
13) What do you mean by infinite loop?
A loop in which the ending condition never occurs is called infinite loop. It repeats forever until the user
intervenes to stop the loop.
14) What is counter controlled loop?
The counter controlled loop depends on the value of a variable known as counter variable. The value of
counter variable is incremented or decremented each time the body of loop executes. The loop
terminates when value of counter variable reaches a particular value.
Long Questions
1) What is nested loop? Give its syntax. Explain its working with an example.
2) Define for loop. Write its syntax. Draw flow chart and explain its working with the help of example.
3) What is do-while loop? Explain its working with example.
4) Write a program that display first five numbers and their sum using while loop.
5) Write a program that prints number form 1-100.
Chapter # 13 Important Short Questions
1) Define function.
A function is a named block of code that performs some actions. The statements written inside the
function are executed when it is called by its name.
2) Why is function used in program?
The real reason of using functions is to divide a program into different parts. These parts of a program can
be managed easily. Once programmer write a function he did not need to write it again.
3) Describe built in function?
Functions that are predefined as apart of language are called built in functions. These are available in
separate files called library files. Example printf(),scanf();
4) Define user define functions.
Functions created by programmer are called user defined functions. Each function is written to perform
specific task. Example fact();
5) What is function prototype?
Function prototype is a statement that provides the basic information that the compiler needs to check
and use a function correctly. Syntax: - Return type Function Name (Parameters List);
6) Differentiate between Function Definition And Function Declaration.
Function Definition Function Declaration
A set of statements that explain what a function Function declaration is a model of function. It is
does is called function definition. It can be written also known as function prototype. It consists of
in following places. function name, function type and parameters list.
1. Before main() Syntax
2. After main() Return type Function Name (Parameters List);
3. In a Separate File
7) What is function Header.
First line of function definition is called the function header.
8) Define function body.
The set of statements which are executed inside the function is known as function body. The body of
function appears after function header. The statements are written in curly braces{}.
9) What is function call statement?
The statement that activates a function is known as function call. A function is called with its name.
Function name is followed by necessary parameters in parentheses(). Parameters are separated by
comma.
10) Differentiate between Local And Global Variable.
Local Variable Global Variable
Local variable are declared inside a body of Global variables are declared outside any function.
function. These are created when control enters These are created as program starts. These
the function. The life time of local variable starts variables exist in memory as long as the program is
when controls enter in function and these variable running. These variables destroyed when program
destroyed as control exists from the function. is terminated.
11) Differentiate between Actual and Formal parameters.
Actual Parameters Formal Parameters / Dummy Parameters
Parameters used in function call are called actual The parameters in function declaration are called
parameters. These parameters are used to send formal parameters. These parameters are used to
values to the function. receive values from the calling function.
12) What is meant by scope of variable?
The area where a variable can be accessed is known as scope of variable.
13) How a function returns value?
Function can return single value. The return type in function declaration indicates the type of value
returned by a function. The keyword return is used to return the value back to the calling function.
14) What is lifetime of a variable?
The duration in which a variable exists in memory is called lifetime of a variable.
15) What is return statement?
The return statement terminated the execution of a function and returns control to the calling function. A
return statement can also return a value to the calling function.
Chapter # 14 Important Short Questions
1) Define Stream.
A logical interface to a file is called a stream. It refers to the flow of data. It served a connection between
the program and data file.
2) Differentiate Binary And Text Stream.
Text Stream Binary Stream
4. It is sequence of characters. 1. It is sequence of byes.
5. It doesnot have one to one relationship 2. It has one to one relationship with
with computer. computer.
6. Characters translation is performed. 3. Character translation not performed.
7. It is less efficient. 4. It is more efficient.
8. Error finding is easy. 5. Error finding is difficult.
3) What is Text file?
A file that stores data s readable and printable character is called text file. A source program of c is an
example of text file.
4) Define EOF Marker.
It is a named collection of characters saved in secondary storage such as disk. A special end character is
used to indicate the end of a text file. It is denoted by EOF in C language.
5) Define Pointer?
Type of variable hat is used to store memory address of a memory cell is known as pointer. By using
pointers programmer can easily access and modify data stored in specific variables.
6) Which function is used to close a file in C language?
A file is closed by using function fclose(). The syntax of this function is fclose (file pointer);
7) Why it is important to close a file?
When the file is close, the file pointer is also destroyed in the memory. The file becomes in accessible.
Closing file is automatic process, if file is not closed, operating system will automatically close it.
8) What is the use of new line marker.
It is used to enter a new line in file. In C \n is use to represents new line marker.
9) What is the use of data file?
This file can be used to store the output of the program permanently. There will be less chances of data
loss.
10) What is the use of data file / file handling?
This file can be used to store the output of the program permanently. There will be less chances of data
loss.
11) List two ways to write text data?
Data can be written character by character with the help of putc() Function. Data can be written in a file
as a string with the help of fputs() Function.
12) List three names of functions used for character input.
1 . scanf() 2. getch() 3. getche()
13) How a file opened in C?
A file pointe is declared and associated with the file to be opened . A function fopen() is used to open a
file. Syntax: - File Pointer = foopen(file name, mode);
14) Define string?
Characters written in double quotation marks are called string. Example “Pakistan”.
15) Define Array?
An array is a group of contiguous memory locations which can store data of the same data type.
Syntax :- data_type array name[n]; n is the subscript of array that shows total number of memory
locations in array.
16) How to declare and initialize String Variable?
Declaring a string variable is the same as declaring an array of type char
Example: - char name*16+=”Lahore”
Punjab College DHA Campus
Part 2 Grand Test Series, 2025
Date Sheet