Note

If you cannot find what you are looking for. Please visit our sitemap

Sunday, 15 May 2016

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

ICS Notes Computer Science 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 the 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 are 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.

Written by: Asad Hussain

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

ICS Notes Computer Science 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

Written by: Asad Hussain & Sana Hussain

Sunday, 8 May 2016

ICS Notes Computer Science Part 2 Chapter 8 Getting Started with C Short Questions

ICS Notes Computer Science Part 2 Chapter 8 Getting Started with C Short Questions


Q 1. What is computer program?
Ans. The set of instructions given to the computer to solve a specific problem is called computer program. Computer can solve problems with the help of computer program. Computer programs are written in programming languages.

Q 2. What is programming language?
Ans. Programming language is used to communicate with computer. All computer programs are written in programming languages. Every programming language has a set of alphabets and rules. The instructions of computer program are written by using the alphabets and rules defined by the programming language.

Q 3. List different types of programming language.
Ans. There are two types of programming languages.

  1. Low level languages
  2. High level languages


Q 4. What is high level language?
Ans. A programming language that is close to human language is called high level language. The instructions written in high level language look like English language sentences. High level languages are easy to learn and understand.

Q 5. What is low level language?
Ans. A language that is close to the language of computer. Computer itself uses this language is called a low level language. There are two types of low level languages.

  1. Machine language
  2. Assembly language


Q 6. What is machine language?
Ans. Machine language is also called binary language. There are only two alphabets of machine language those are zero (0) and one (1). Computer can understand only machine language. The programs written in other programming languages are first translated to machine language, and then used on computer. It is called the native language of computer.

Q 7. What is assembly language?
Ans. It is a programming language in which machine language instructions are replaced by english like words. These words are known as mnemonics. It is pronounced as Ne-Monic. An assembly language used english like words. It is easy to write a program in assembly language. It is mostly used for system software.

Q 7. What is source program?
Ans. A computer program written in high level language is called source program. Source program is also called source code.

Q 8. What is object program?
Ans. A computer program in machine language is called object program. Object program is also called object code. Machine language is native language of computer so object program directly runs on computer.

Q 9. What is language translator?
Ans. A language processor is a software that converts a program written in any programming language into machine language. Every language has its own processor. Language processor is also called language translator.

Q 10. What is compiler?
Ans. Software that converts a high level language program into machine language is called compiler. Every language has its own compiler. First a program is written in high level language. Then it is given to compiler. Compiler detects and tells about errors is programs. When high level language program is error free compiler converts it into machine language.

Q 11. What is interpreter?
Ans. It is a program that converts a source program into object program one statement at a time. It takes one statement of source program, translates it in machine code and executes it. After the execution of one statement, it takes next statement and repeat this process till the last instruction of program.

Q 12. What is assembler?
Ans. It is a language translator that converts a program written in assembly language into machine language.

Q 13. What is structured programming language?
Ans. In structured programming language the program is divided into parts or modules. These modules are combined to make a complete program. It is easy to write and debug a program written in structured programming language. There is less chance of error.

Q 14. What is unstructured programming language?
Ans. In unstructured programming language whole program consists of a single unit. It does not consist of parts or modules. It is difficult to write and debug a program written in unstructured programming language. There is more chance of error.

Q 15. What is preprocessor?
Ans. A compiler is a program that translates a high level language program into machine language. This process is called compilation. Preprocessor is a program that modifies a C program before compilation. Preprocessor directives are instructions for the preprocessor.

Q 16. What is preprocessor directive?
Ans. Preprocessor directives are instructions for the preprocessor. These instructions are written at the beginning of the program. Every preprocessor directive starts with # symbol. After # symbol "include" or "define" directives are used. Preprocessor directives are also called compiler directives.

Q 17. What is the work of include directive?
Ans. Include is a preprocessor directive. It is used to include header files in to the program. The relevant header file of the library function, we want to use in programs are mentioned at the beginning of program by using include directive.

Q 18. What is the work of define directive?
Ans. Define preprocessor directive is used to define a constant macro. Its general syntax is:

  • #define Macro-Name expression

Q 19. What is statement terminator?
Ans. Every C language statement ends with semicolon ";". Semicolon at the end of statement is called statement terminator.

Q 20. What are delimiters?
Ans. Curly braces at the beginning and end of the main function are called delimiters. C language statements are written between delimiters.

Q 21. What is main function?
Ans. Every C language program must contain a main() function. A program with out main function cannot be executed. Instructions of programs are written between the curly braces {} of main() function. These statements enclosed in main() function are called body of the main() function.

Q 22. What are bugs and debugging?
Ans. While writing a program the programmer may come across many errors. The error in a program is called bug. The process of finding and removing errors is called debugging.

Q 23. What is meant by creating a program?
Ans. Writing source code statements is called creating C program. Turbo C IDE can be used to create and edit program. First open Turbo C IDE. Then select new from file menu. A new edit window will be opened. The cursor blinks in the window. Cursor control keys can be used for cursor movements. We write the program statements in the window and save it as a program file.

Q 24. What is meant by editing a program?
Ans. Writing and editing source program is the first step. Source code is written in C language according to the type of the problem, in any text editor. Changing source code and removing errors in the program is called editing a program.

Q 25. What is meant by compiling a program?
Ans. Computer does not understand C language. It understands only machine language. So C language code is converted into machine language. The process of converting source code in to machine code is called compiling. Compiler is a program that compiles source code. If compiling is successful source program is converted into object program. Object program is saved on disk. The extension of file is ".obj".

Q 26. What is meant by linking a program?
Ans. The process of combining required library functions with object program is called linking. This is done with the help of a program called linker. It is a part of compiler. The linker combines object program produced by compiler and library function. It produces and saves a final machine language file. This file is called executable file. The extension of executable file is ".exe".

Q 27. What is meant by executing a program?
Ans. The process of running an executable file is called executing. After linking C program can be executed. A program loader is used to to transfer executable file from secondary storage to main memory. The program can be executed by selecting run from run menu bar of Turbo C IDE or by pressing Ctrl + F9 keys from keyboard.
Q 28. List name of some high level language.
Ans. High level languages

  • C
  • C++
  • C#
  • COBOL
  • BASIC
  • FORTRAN
  • PASCAL
  • JAVA


Q 29. What is Turbo C++?
Ans. Turbo C++ is an Integrated development environment (IDE) for creating C and C++ programs. Borland international has developed it. It is also called TC editor. It is used to create, edit and save programs. It also has powerful debugging features. These help us in finding and removing errors from a program. We can easily compile program. Linking a program is also very easy. It is also used to execute a program.

Q 30. What are necessary step to prepare a C program?
Ans. Step to prepare a C program
  • Creating & Editing
  • Saving
  • Compiling
  • Linking
  • Loading
  • Running


Q 31. What are header files?
Ans. Header files are part of C compiler. C language provides many built-in programs. Every program has a unique name. These programs are called built-in functions or library functions. Every library function can perform a specific task. We can use these library functions in our C language program. These functions are divided into groups according to their functionality. A group of same type of functions are stored in a same file. This file is called header file.

Q 32. What is C statement?
Ans. Every instruction written in C language program is called a C statement. Every statement ends with a semicolon ";". Semicolon is called statement terminator.

Q 33. What are syntax errors?
Ans. The rule for writing a program in a specific programming language is called syntax of the language. We must follow the syntax of a language. Syntax error occurs when the statements of program are not according to syntax. Compiler detects syntax errors. If there is a syntax error in program. It cannot be compiled successfully. Compiler tells about the location and type of syntax error. Syntax errors can be removed easily.

Q 34. What are logical errors?
Ans. The error that is due to wrong algorithm is called logical error. These errors occur due to the wrong logic of program. Compiler cannot detect these errors. A program having logical errors gives wrong results on execution. These errors are difficult to find, as compiler cannot detect these errors. The programmer should examine the whole program to find logical errors.

Q 35. What are runtime errors?
Ans. These errors occur during the execution of program are called runtime errors. When runtime error occur the execution of program stops and computer shows an error message. These errors occur when program wants to perform such task that computer cannot perform.

Q 36. What is ANSI C?
Ans. C language is very powerful and flexible language. Wide range of application programs are written in C language. American National Standard Institute (ANSI) made standard version of C language in late 1980s. This standard version of C is also called ANSI C. New version of C has many new features that were not available in older versions.

Q 37. List any four advantages of C language?
Ans. Advantages of C language

  • Easy to learn
  • Easy to Remove Errors
  • Machine Independence
  • Standard Syntax
  • Shorter Programs


Q 38. What is meant by machine independence?
Ans. A low level language program can run only on the type of computers for which it is written. So low level languages are machine dependent. A program written in high level language is machine independent. It can run on all types of computers.

Q 39. What is the difference between compiler and interpreter?
Ans. Software that converts a high level language program into machine language is called compiler. Every language has its own compiler. Compiler detects and tells about errors is programs. When high level language program is error free compiler converts it into machine language. So compiler is software that converts a source program into object program as a whole. Object code is used for execution.
It is a program that converts a source program into object program one statement at a time. It takes one statement of source program, translates it in machine code and executes it. Each time we execute a program by using its source code.

Written by: Asad Hussain

Sunday, 1 May 2016

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

ICS Notes Computer Science 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. A large number of 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 Preprocessor 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 according to 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 perform 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 into 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.

Written by: Asad Hussain  &  Sana Hussain

ICS Notes Computer Science Part 2 Chapter 14 File Handling in C Short Questions

ICS Notes Computer Science Part 2 Chapter 14 File Handling in C Short Questions


Q 1. What is data file?
Ans. A data file is a collection of related records. A records is a collection of fields. Any type of data can be stored in data files. Data in data files is stored permanently.

Q 2. What is stream?
Ans. The flow of data from one point to another is called a stream. The point from where data is sent is called source and the point where data is received is called destination.

Q 3. What are different types of streams?
Ans. There are different types of streams used for transfer of data. These are
  • Input stream
  • Output stream
  • Binary stream
  • Text stream


Q 4. What is text stream?
Ans. A flow of characters from a source to a destination is called text stream. In text stream characters are converted in to bytes. There is no one to one relation between the characters and the bytes. The number of characters and the number of bytes may not be same when characters are converted in to bytes. For example, a new line is stored as a carriage return and line feed pair.

Q 5. What is binary stream?
Ans. A flow of bytes from a source to a destination is called binary stream. No translation is required in binary stream. There is one to one correspondence between the bytes read or written and those on external device. Binary stream is used to transfer any types of data.

Q 6. What is input stream?
Ans. The flow of data from a source to a program is called input stream. For example C language program reads data from a data file. This flow of data from data file to C program will be input stream.

Q 7. What is output stream?
Ans. The flow of data from a program to a destination is called output stream. For example C language program write data to a data file. This flow of data from C program to data file is termed as output stream.

Q 8. What is pointer?
Ans. Variable are named memory locations used to store data. Different types of variable can store different types of data. Pointer is a special type of variable. It is not used to store data. It is used to store memory address used by another variable. Like variable, there are different types of pointers. The type of pointer should match the type of variable whose address it is holding.

Q 9. What is file pointer?
Ans. File pointer is a pointer type variable whose type is File. File is a special data type defined in stdio.h header file. When a file is opened it transfers from secondary storage to main memory. File pointer variable contain information about an opened file. Data files can be accessed with the help of File pointer. File pointer is used to read and write in a data file.

Q 10. What is meant by EOF?
Ans. Text files are stored on secondary storage. Different files have different size. A special end of file marker is used at the end of each text file. This marker is placed after the last character of text file. In C language is is denoted by EOF. EOF is used to detect the end of file.

Q 11. What is a string?
Ans. A collection of character enclosed in double quotations is called a string. The variable that is used to store a string is called string variable. C language does not provide any special data type to store string. As string is a combination of characters, a char array is used to store string.

Q 12. What is the purpose of fopen() function?
Ans. A file must be opened before use. We can read from or write into a file only if it is opened. Files are permanently stored on secondary storage. When a file is opened it's data is transferred in main memory. Header file stdio.h contain all standards file handling functions. fopen() function is used to open a file. A file pointer is attached with an open file.

Q 13. What is the purpose of fputs() function
Ans. fputs() function is used to write a string in text file. This function is defined in stdio.h header file before the use of this function the file must be open in write mode or append mode. The general syntax of this function is as follow

  • fputs( string, file pointer);


Q 14. What is the purpose of fgets() function
Ans. fgets() function is used to read a sting from a text file. This function is defined in stdio.h header file. Before the use of this function the file must be opened in read mode. The general syntax of this function is as follow:

  • fgets( str, n, file pointer);


Q 15. What is the purpose of putc() function
Ans. The putc() function is used to write a single character into text file at one time. Before the use of this function file should be opened is write or append mode. The syntax of this function is as follow:

  • putc( character, file pointer);


Q 16. What is the purpose of getc() function
Ans. getc() function is used to read a single character from a file. More than one characters can be read from a file by using this function repeatedly. Before the use of this function the file must be opened in read mode.

Q 17. What is the purpose of fprintf() function
Ans. The fprintf() function is used to write data in a file in specified format. Any type of data can be written in a file. The file must be opened in write or append mode before the use of this function. Its general syntax is as follow:

  • fprintf( fp, Format_string, argument);


Q 18. What is the purpose of fscanf() function
Ans. The fscanf() function is used to read data from a file in specific format. It works like scanf() function but scanf() function take data from keyboard. Its general syntax is as follow:

  • fscanf( fp, Control-string, Var);


Q 19. What is the purpose of fclose() function
Ans. When a file is open it is transferred from secondary storage to main memory. A connection is established between C program and file with the help of file pointer. When a file is closed its contents are transferred from main memory to secondary storage. Its connection with C program breaks. File pointer is destroyed and data of file becomes inaccessible. If a file is not closed properly some data may lose. The function fclose() is used to close a file opened by fopen() function.

Written by: Asad Hussain  &  Sana Hussain