Training COMSATS University Vehari Campus

Receiving Certificate from Syed Majid Ali Shah (Deputy Director Information) on 14-01-2015 by Punjab Emergency Service (Rescue 1122)

PM’s Laptop Scheme for Talented Students

Receiving Laptop from Dr. Khair-uz-Zaman (Director COMSATS University Vehari Campus) on 18-02-2015 under Prime Minister’s Laptop Scheme

Convocation SP16 COMSATS University Vehari

Receiving BS (Computer Science) Degree on 07-10-2016 at COMSATS Vehari Campus from Dr. S. M. Junaid Zaidi rector COMSATS University

ESE's Training by QAED GHSS Karampur

Receiving Certificate of Induction Training of ESE's by QAED on 29-08-2017 from Mahmood Arshad Principal GHSS Karampur

SSE (CS) Induction Training by QAED

Receiving Certificate of QAED on 29-08-2017 by Ch. Muhammad Maroof D.E.O (M-EE) Vehari and Afzal Bhatti Principal Govt. Model HSS Vehari

Training on e-Library and e-Learn Punjab

Visited e-Library Vehari on 05-11-2018 for Training of e-Learn using Multimedia Classroom in SED and e-Library

Sunday, June 17, 2018

Chapter 13 Functions in C


Computer Notes ICS Part 2 Chapter 13 Functions in C Short Questions

Q 1. What is modular programming?
Ans. A programming technique in which a program consists of many independent parts is called modular programming. These parts are called modules. These parts are also called function. Each module can perform different tasks. The development speed of a program increases as different programmers can write different modules of a program. Different modules are combined to make a 
complete program.

Q 2. What is a function?
Ans. In structured programming the program consists of more than more one part. Each part of program is called a module or function. Every function is given a unique name and it is developed to perform a specific task. So, function can be defined as " A named piece of code developed to perform a specific task is called function".

Q 3. Why functions are used?
Ans. Function is a piece of code designed to perform a specific task. There are many advantages of using functions. These advantages are described below:


·                     Easy programming
·                     Easy modification
·                     Easy debugging
·                     Reuse-ability
·                     Eliminates duplicate code
·                     Less programming time


Q 4. What are built-in functions?
Ans. The function that are provided as a part of 
C language are called built-in functions. These functions are also called library function. Many built-in functions are provided by C language. These functions are stored in different header files. If we want to use a built-in function in a program the relevant header files is included at the start of the program in Pre-processor directive.

Q 5. What are user defined functions?

Ans. The functions that are written by the programmer to perform specific task are called user defined functions. These functions are written per the requirement of the program.

Q 6. What is function prototypes?
Ans. Function declaration is also called function prototype. It is a statement that provides 
basic information to compiler about the structure of the function like other C language statement, function declaration statement also ends with semicolon. Function declaration is necessary like variable declaration. A function must be declared in a C language program. Function can be declared before the main () function or inside the main () function.

Q 7. What is function definition?
Ans. Every function performs some specific task. The task is performed when the set of instructions execute. Writing set of statements of a function is called function definition. Function definition is always done outside main () function.

Q 8. What is function header?
Ans. The first line of the function definition is called function header. Its general syntax is as follow:


·                     Return-Type Name(parameters)


Q 9. What is function calling?
Ans. The statement that is written to use a function is called function call. A function can be called at any point in the program. A function is called by using its name. The required parameters are maintained after the name in braces at the end of the function call statement. Semicolon is used at the end of statement in which function is called.

Q 10. What is return statement?
Ans.  Keyword "return" is used to return a value from the body of called function to calling function. The statement in which "return" keyword is used is called return statement. The general syntax for return statement is as follow:
return expression;

Q 11. What are parameters?

Ans. Parameters are also called arguments. These are the values that are provided to a function when it is called. when function is called, parameters are written after function name in parenthesis. These parameters can be variables or 
constants. More than one parameter is separated by comma.

Q 12. What is a local variable?
Ans. The variables declared inside main () function, inside any user defined function or header of function definition are called local variables. Local variable also called automatic variables. The general syntax to declare a local variable is as 
follows:
auto data-type variables-name;

Q 13. What is global variable?

Ans. The variables that are declared outside the main () function or any other function are called global variable. Global variables are also called external variables. Global variables can be used by all functions in the program. All functions can share their value. If value of a global variable is changes in a function, that changes value is also available in other functions.

Q 14. What is meant by life time of a variable?

Ans. Lifetime of a local variable is limited, when control enters the function and variable declaration statement is executed, they are created in memory. When the control exits from the function these variables are destroyed and their life ends, when variables are destroyed the data stored in them also becomes inaccessible.

Q 15. What is meant by scope of a variable?
Ans. Local variables have a limited scope they can only be used in the function in which they are declared. Compiler generates an error if we want to access a local variable, outside its scope.

Q 16. What is scope of global variable?

Ans. Global variables can be accessed in all modules of program. They are accessible in main () function as well as all other user defined functions.

Q 17. What is life time of global variable?
Ans. When program starts execution, global variables are created in memory. They remain in memory till the termination of the program. When the program is terminated, global variables are destroyed from the memory. Therefore, life time of a global variable is between starting and termination of program.

Chapter 12 Loop Constructs of C


Computer Notes ICS Part 2 Chapter 12 Loop Constructs of C Short Questions

Q 1. What is a loop?
Ans. The repeatedly execution of a statement or set of statement is called a loop. In loop the statement or set of statements executes for several times or until the condition remains true. The statement or set of statement that are executed repeatedly is called the body of the loop. Looping structures is also called iterative or repetitive 
structure.

Q 2. Why loops are used?
Ans. The repeatedly execution of a statement or set of statements is called a loop. In loop the statement or set of statement executes for a fix number of times or until the condition remains true. Loops are used to do similar or same tasks repeatedly.

Q 3. What are different types of loops available in C language?
Ans. In 
C language, there are three types of loop statements


·                     while loop
·                     do-while loop
·                     for loop


Q 4. What is while loop?
Ans. It is a 
conditional loop statement. It executes a statement or a set of statement repeatedly until the given condition remains true.
The syntax of while loop is
while (condition)
statement;

Q 5. What is do-while loop?
Ans. It is a loop structure that is used to execute a statement or set of statement repeatedly as long as the given condition remains true its working is similar to while loop but condition comes after the body of the loop.
The syntax of a do...while loop in 
C programming language is
do {
   statement(s);
} while (condition );

Q 6. What is the difference between while and do-while loop?
Ans. While Loop


·                     Condition comes before the body of the loop.
·                     If condition is false at beginning body of the loop dose not execute.
·                     Semicolon (;) is not used at the end of the while statement.


Do-while Loop



·                     Condition comes after the body of the loop.
·                     The body of the loop is executed once even if the condition is false at the beginning.
·                     Semicolon (;) is given at the end of the do-while statement.


Q 7. What is for loop?
Ans. 'for' is keyword of C language. 'for' statement is used as a loop statement. It is used to execute a statement or set of statement repeatedly for a specific number of times. It is also called counter loop.
The syntax of a for loop in C programming language is
for (init; condition; increment) {
   statement(s);
}

Q 8. What is nested loop?
Ans. A loop within the body of another loop is called nested loop. Any loop statement can be used with in the body of any loop statement. For example, a while can be used with in the body of for loop. The nesting can be done up to any level. If the nesting level is increased the working of loop becomes complex.
The syntax for a nested for loop statement in C is as 
follows
for (init; condition; increment) {

   for (init; condition; increment) {

      statement(s);
   }
 
   statement(s);
}

Q 9. What is go to statement?
Ans. goto statement is used to transfer flow of control to a named label, it is an unconditional statement. The label should be in same function. The syntax of goto statement is
goto label;
               _________________
               _________________
               _________________
Label;

Chapter 11 Decision Structures of C


Computer Notes ICS Part 2 Chapter 11 Decision Structures of C Short Questions

Q 1. What is Control structure?
Ans.  A control 
structure is a statement used to control flow of execution in a program or function. Control structure is used to combine individual instructions in to a single logical unit. This unit has one entry point and one exit point. Program logic is implemented with the help of control structures. Three kinds of control structures are used to control flow of execution of instructions. These are as follow:


·                     Sequence structure
·                     Selection structure
·                     Repetition structure


Q 2. What is meant by sequence structure?

Ans. In sequence structure the instructions of program executes one after the other in the order in which they are written. It is also called the default flow of a program. The program starts execution from the first instruction and all instructions are executed one by one in a sequence.

Q 3. What is meant by selection structure?

Ans. In selection structure the instructions of the program are divided into two or more groups. Selected group of instructions are executed. This selection is done after evaluation of a certain condition.

Q 4. What is meant by repetition structure?

Ans. Repetition structure is also called iteration structure or loop structure. It is used to execute a statement or set of statement repeatedly as long as the given condition remains true. This control structure is used to repeat same or similar work. There are three basic loop structures in 
C language. These are as follow:


·                     While loop
·                     Do-while loop
·                     For loop


Q 5. What is IF statement?

Ans. "if" is a keyword in C language. "if" statement is the simplest form of selection structure. It is used to execute or skip a statement or a set of statements after testing a condition. The condition should be a logical or relational expression. After evaluation if the result of condition is true the statement or set of statements after "if" statement executes. If the result of the condition is false, the statement or the set of statements after "if" statement is skipped.
The general syntax of if statement is
if(condition)
Statement; 

Q 6. What is compound statement?

Ans. A set of statements enclosed in 
curly brackets is called compound statement. It is also called block of code.

Q 7. What is if-else statement?

Ans. ""if" statement is used to make a decision whether a particular task will be performed or not. If we want to make a two-way decision if-else statement is used. After evaluation of condition one from two code blocks will be executed and the other will be skipped. We cannot execute or skip both code blocks.
The general syntax of if-else statement is
if(condition)
Statement;
else
Statement; 

Q 8. What is if-else-if statement?

Ans. if-else-if statement is used to execute one compound statement from two of more statements.  If there are more than two compound statement and we want to choose one from them if-else-if statement is used.
The general syntax of if-else-if statement is
if(condition 1)
Statement 1;
else if(condition 2)
Statement 2;
.

else if(condition n)
Statement n;.
else
Default statement;

Q 9. What is conditional operator?

Ans. 
Conditional operator is used as an attribute of simple if-else statement. It is used to make two way decision.
The general syntax of conditional operator is
(Condition)? Statement 1 : Statement 2;

Condition should be a logical or relation expression. After evaluation if the result of condition is true then statement 1 is executed. If result of condition is false then statement 2 is executed.

Q 10. What is switch statement?

Ans. Switch statement is an alternative of if-else-if statement. It is also a conditional statement. It is used when we want to execute a block on statements from multiple blocks.
The general syntax of switch statement is
Switch (expression) {

case constant-expression:

statement (s);
break;
case constant-expression:
statement (s);
break;
default:
statement(s);
}

Q 11. What is nested if statement?
Ans. The use of an "if" statement is used with in another "if" statement is called nested if statement.
The general syntax of nested if statement is
If (Condition 1)
{

If (Condition 2)

{
Statement;
}
}

Q 12. What is break statement?

Ans. Break is a keyword. It is the last statement in each case. It is used to transfer flow of control outside a code block. When break statement executes in switch statement the flow of control is transferred to the first instruction after switch block.

Chapter 10 Input Output of C


Computer Notes ICS Part 2 Chapter 10 Input Output of C Short Questions

Q 1. What is input statement?
Ans. The data or instructions given to a program are called input. The data is provided to program by using some input device. Keyboard is standard input device. The input given by keyboard is called standard input. The C language instructions that are used to take input are called input statements.

Q 2. What is output statement?

Ans. The processed input data produced by program is called output. Output is sent by program to some output device. The standard output device is monitor. So, the output sent to monitor is called standard output. In C language, built-in functions are used for output. The C language instruction that is used to send output is called output statement.

Q 3. What are standard input functions?

Ans. Some important functions used for standard input are:


·                     scanf()
·                     gets ()
·                     getch()
·                     getche()


Q 4. What are standard output functions?

Ans. Some important functions used for standard output are:


·                     printf()
·                     puts ()


Q 5. What are is printf() function?

Ans. printf() function is used to send output of the program towards monitor. It can display text, constants or value of variables on monitor. It can display text, constants and value of variables in our desired format. It is also called formatted output function. It is a library function defined in stdio.h header file. The syntax of printf() function is as follow:
printf("string");

Q 6. What is a format specifier?

Ans. A string that is used to specify the format in which the value of the variable will display on monitor is called format specifier. Format specifier start with % symbol. It is also used to specify the format according to which the values will be displayed on output device or read from an input device. The general syntax of format specifier is as follow:


·                     % Flag Field_Width Precision Conversion_Character


Q 7. What is field width in format specifier?

Ans. The number of columns used to display a value on monitor screen is called field width. A number in format specifier that determines the field width is called field width specifier. It specifies the minimum number of columns that should be used to print a value. It used is optional in format specifier.

Q 8. What is an escape sequence?

Ans. A combination of characters in printf() function used to control printing on the output device is called escape sequence. Escape sequence are not printed. Escape sequence begins with backslash (\). A specific character is used after backslash. Escape sequence can be used at the beginning, middle or end of a string. Any number of escape sequence can be used in a string.

Q 9. What is getch() function?

Ans. This function is used to take a single character as input from keyboard. The character taken from keyboard is transferred to variable. After typing a character there is no need to press enter key. It is used to transfer a character to a variable without pressing enter key. The character typed does not appear on screen.

Q 10. What is getche() function?

Ans. The function getche() is used to take a single character as input from keyboard.  The character taken from keyboard is transferred to char type variable. After typing a character there is no need to press enter key. It is used to transfer a character to a variable without pressing enter key.

Q 11. What is the function of \n escape sequence?

Ans. New line: It is used to move the cursor at the beginning of next line.
For example
printf("Hello \n Pakistan");

The output of the above statement will be
Hello
Pakistan

Q 12. What is the function of \t escape sequence?

Ans. Tab: It is used to move the cursor on one tab forward from current position.
For example
printf("Hello \t Pakistan");

The output of the above statement will be
Hello Pakistan

Chapter 9 Elements of C


Computer Notes ICS Part 2 Chapter 9 Elements of C Short Questions

Q 1. What is an identifier?
Ans. In a program the names that are used to represent variables, constants, types, functions and labels are called identifiers. We can use any number of characters as identifiers but the first 31 are significant to C compiler.

Q 2. What is user defined identifier?

Ans. User defined identifiers are the names assigned by the programmer to functions, data types, variables etc. in a program. For example, age, r no can be user defined identifier in a program.

Q 3. What is standard identifier?
Ans. The identifier that have a special meaning in C language are called standard identifiers. These identifiers can be redefined. But this is not recommended. If we redefine a standard identifier in a program C compiler cannot use it for its original purpose. For example, printf and scanf are standard identifiers.

Q 4. What is a keyword?
Ans. The words that have predefined meanings and purpose in C language are called keywords of C language. These are also called reserved words. The purpose of keywords is predefined. They cannot be used for any other purpose in C language programs. All keywords are written in lower case. Keywords cannot be used as identifiers. In C language 32 words are defined as keywords.

Q 5. What is a variable?
Ans. Computer programs are developed to solve different problems. In these problems, different types of data is used as input. Programs process data and generate output. The data given as input is stored in the main memory for processing. After processing the results are also stored in main memory. Main memory is a collection of bytes. These bytes are also called memory locations. So " The named memory locations used to store input data and result, during the execution of the program is called variable".

Q 6. What is a constant?
Ans. The quantity whose value cannot be changed during the execution of the program is called constant. Constants can be declared like variable. To declare a constant 'const' keyword is used. For example,


·                     const int x = 10;


Q 7. What is meant by variable declaration?
Ans. Specifying variable name and the type of data it can contain is called variable declaration. C is a strongly typed language. In C language, a variable must be declared before it is used to store data. If we use a variable without declaration compiler will generate an error at compile time.

Q 8. What is variable initialization?
Ans. Storing a value in variable at declaration time, is called initialization. When we declare a variable, some memory is allocated to it, per its type. This memory already contains some data. This meaningless is called garbage. If we use variable without assigning a value, the result will not be correct. We should initialize a variable before using it.

Q 9. What is meant by typed language?
Ans. Specifying variable name and the type of data it can contain is called variable declaration. C is a strongly typed language. In C language, a variable must be declared before it is used to store data. If we use a variable without declaration compiler will generate an error at compile time.

Q 10. What are different types of constants?
Ans. The quantity whose value cannot be changed during the execution of program is called a constant. Constant can be declared like variable. To declare a constant 'const' keyword is used. There are two types of constants in C language.


·                     Numeric constants
·                     Character constants


Q 11. What is meant by data type?
Ans. Computer programs are used to solve different types of problems with computer. Computer program take data as input, process it and produce results in the form of output. Computer program can process different types of data. Data type is defined as the set of values and a set of operations allowed on those values. It also tells us about the memory required to store that data.

Q 12. What is meant by standard data type?
Ans. Data types that are defined as the part of the language are called standard data types. For example, int, char, etc. are standard data type in C language.

Q 13. What is meant by user defined data type?
Ans. In addition to standard data types user can define its own data type. These data types are known as user defined data types. Standard data types can be used in all C language program but user defined data type can only be used in a program in which it is defined.

Q 14. Which data types can be used to store integer data?
Ans. Data types for Integers


·                     int
·                     short int
·                     long int
·                     unsigned int
·                     unsigned long int


Q 15. Which data types can be used to store floating-point data?
Ans. Data types for Real Numbers


·                     float
·                     double
·                     long double


Q 16. What is cancellation error?
Ans. Cancellation error occurs when an arithmetic operation is performed between very large and a very small floating point number. Due to this error computer produces unexpected results. If a large number and a small number are added the large number may cancel out the small number. For example, if we add 1872.0 and 0.0000000005747 the result may be 1872.00000.

Q 17. What is meant by underflow?

Ans. When a value is stored in a variable that is less than its minimum range, that value cannot be stored in it properly. An error occurs. This error is called underflow error. For example, if we store a number less than -32768 in an int type variable an underflow error will occur.

Q 18. What is meant by overflow?
Ans. When a value is stored in a variable that is greater than its maximum range, that value cannot be stored in it properly. An error occurs. This error is called overflow error. For example, if we store a number greater than 32767 in an int type variable an underflow error will occur.

Q 19. What is character data type?
Ans. To store a character data type chat is used. char type variable use one byte in memory. Character values are enclosed in single quotes in C language for example '?', 'a'. When we store a character in char type variable, ASCII value of that character is stored in it. ASCII stands for American Standard Code for Information Interchange. In this code, each character is assigned a unique numeric value that value is called ASCII code for that character.

Q 20. How are characters stored?
Ans. When we store a character in char type variable, ASCII value of that character is stored in it. ASCII stands for American Standard Code for Information Interchange. In this code, each character is assigned a unique numeric value that value is called ASCII code for that character. For example, ASCII code of 'A' is 65 and 'B' is 66. As char type variable contain numeric ASCII code, arithmetic operation can be performed on them.

Q 21. What is an operator?
Ans. In computer programs, we perform different types of operations on data. Operators are symbols that are used to perform different operation on data. There are different types of operators in C language. For example, + symbol is used to add two numeric values written on both sides.

Q 22. What are different types of operators?
Ans. Different types of operator available in C language are


·                     Arithmetic operator
·                     Relational operator
·                     Logical operator
·                     Increment and Decrement operator
·                     Assignment operator


Q 23. What is an arithmetic operator?
Ans. The operator that are used to perform arithmetic operation on numeric data are called arithmetic operators. These operations can operate on numeric variable or constants.

Q 24. What is an assignment operator?
Ans. The symbol = is called assignment operator. It is used to store a value of a result of an expression in a variable.

Q 25. What is an assignment statement?
Ans. A C language statement in which assignment operator is used is called assignment statement. The general form of an assignment statement is


·                     variable = expression.

It is used to assign a value or result of an expression to a variable. The name of variable is always written on the left side of assignment operator. The value or expression is always written on the right side of assignment operator.

Q 26. What is compound assignment?
Ans. An assignment statement that is used to assign one value to more than one variable is called compound statement. The assignment operator = is used more than once in this statement. For example,


·                     A = B = 10;

In above statement a value 10 is assigned to both variables A and B.

Q 27. What is compound assignment operator?
Ans. A combination of assignment operator with arithmetic operator is called compound assignment operator. These are also used to perform arithmetic operations. For example, +=. -=, *=, /=, %= are compound assignment operator.

Q 28. What is increment operator?
Ans. A double plus (++) sign is called increment operator. It is a unary operator. It is used to add 1 to the current value of a variable. It cannot be used with a constant or an expression. It can be used before or after the variable. For example,
x++ and ++x are valid but 14++ is not valid.

Q 29. What is decrement operator?
Ans. A double minus (--) sign is called decrement operator. It is a unary operator. It is used to subtract one from the current value of a variable. It cannot be used with a constant or an expression. It can be used before or after the variable name. For example,
x-- and --x are valid but 14-- is not valid.

Q 30. What is relational expression?
Ans. A combination of relational operators and operands is called relational expression. The operands
may be constants or variables. Operands should be of same type. After evaluation, a relational expression generates True or False.

Q 31. What are logical operators?
Ans. The symbols used in compound expression are called logical operators. AND, OR and NOT are logical operators available in C language.

Q 32. What is logical expression?
Ans. A combination of relational expression and logical operators is called a logical expression. It is used for calculation. Its evaluation gives a single numeric value.

Q 33. What is AND operator?

Ans. If the relational expression on both sides of AND generates true, the final result is true. It is represented by && symbol.

Q 34. What is OR operator?

Ans. If any of the relational expression on both sides of OR generates true, the result is true. It is represented by || symbol.

Q 35. What is NOT operator?
Ans. It is used to convert true to false and false to true. It is represented by ! symbol.

Q 36. What is meant by operator precedence?
Ans. The order in which different types of operators in an expression are evaluated is called order of precedence of operator. It is also called hierarchy of operator’s different types of operators has different precedence level. The operators having high precedence are evaluated first.

Q 37. What is an expression?

Ans. A combination of operators and operands is called expression. Expression are used to calculate the values of formulas. The evaluation of an expression gives a single value. The operands of an expression may be constants or variable. For example, a + b, a + 5, and 5 + 6 are all expressions.

Q 38. What are comments?
Ans. In C language program the lines written between /* and */ are considered as comments. The compiler ignores these lines. These are used to add remarks in the program.
Comments are also used to explain the logic of the program. Comments are used to increase the readability of the program. Comments can be added anywhere in the program.

Q 39. What is a single line comment?
Ans. In C language program the lines written between /* and */ are considered as comments. The compiler ignores these lines. These are non-executable statements. These are used to add remarks in the program. If a comment consists of one line it is called single line comment. Single line comment can be made using // it has no ending it consists of only one line.

Q 40. What is multi line comment?
Ans. In C language program the lines written between /* and */ are considered as comments. The compiler ignores these lines. These are non-executable statements. These are used to add remarks in the program. If a comment consists of more than one line, then it is called multi line comment.

Q 41. What is prefix increment?

Ans. If increment operator is written before the variable name, then it is called prefix increment operator. For example, ++x. In this case of prefix increment the value of variable is incremented by one and then it is used.

Q 42. What is postfix increment?
Ans. If increment operator is written after the variable name, then it is called postfix increment operator. For example, x++. In this case of postfix increment first the value of variable is used then incremented by 1.

Q 43. What is prefix decrement?
Ans. If decrement operator is written before the variable name then it is called prefix decrement operator. For example --x. In this case of prefix decrement first the value of variable is decremented by one and then it is used.

Q 44. What is postfix decrement?
Ans. If decrement operator is written after the variable name then it is called postfix decrement operator. For example x--. In this case of postfix decrement first the value of variable is used then decremented by 1.