0% found this document useful (0 votes)
42 views39 pages

Important Question PPS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views39 pages

Important Question PPS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

PPS- 3110003

Important Question for Examination

1. Draw block diagram of computer system and explain its various components

2. Enlist types of operators and explain any two in detail with example.

3. Explain putchar(), puts(), getchar(), getch(), getche(), scanf(), printf() functions


with suitable example.

4. What is Flowchart and Algorithm? Enlist various symbols used in Flowchart

5. Differentiated between Hardware and Software. Explain System Software.

6. Describe following string functions in C – Language.


(1) strcpy( ) , (2) strcat( ) , (3) strlen( ) , (4) strcmp ( )

7. What is array? Give example and advantages of array. Explain initialization of an


array value by example

8. Define following terms:


Keywords, Identifiers, Machine Language, System Software, Compiler,
Assembly Language, Interpreter.

9. Explain how string is defined in C. List the various inbuilt string functions

10. Enlist branching statements with suitable example. For loop, do while loop, while
loop with syntax.

11. Explain the use of following statements.


(I) break (II) continue (III) goto

12. List out basic data types in C with its Memory size.

13. Explain Entry controlled loop and Exit controlled loop with appropriate flow
chart.

14. Show 1D array, 2D array declaration, initialization and iteration.

15. What is conditional statement? Describe If, else If, nested Else If, Else if ladder
and switch case statement with example.

16. Explain the concept of Pointers. What is Array of Pointers?

17. Give a difference between User-Define function and Library Function.

18. List out category of functions.

19. Difference between Local variables and Global variables.

20. Difference between call by value and Call by reference.


21. Explain Recursion.

22. List out storages classes of variable.

23. Give difference between Structure and Union.

24. What is Dynamic Allocation? List out memory allocation functions.

25. List out various mode of File open. Also discuss File Function.

Note:
 This is important questions which were asked in previous year GTU external examination
(both Regular as well as remedial)
 Answer of this questions are given below.
 In exam, if it is asked any question from above list then you need to write their answer
according to their marks weightage (like 3 marks, 4 marks, 7 marks as per GTU paper style)
 For the programs, you need to refer practical list. Any question from that can be ask in final
exam.
1. Draw block diagram of computer system and explain its various components
Ans:
There are basic five components which are
1. Central Processing Unit (CPU) (ALU and CU)
2. Memory
3. Input Device
4. Output Device
5. Secondary Storage Device
Central Processing Unit
 The Central Processing Unit (CPU) is also known as “brain” of the computer system.
 Based on Instruction it received, the CPU performs operation on data.
 It is also responsible for controlling the data that is flowing from the computer system.
CPU consist of (ALU + CU = CPU)
1. Arithmetic Logic Unit (ALU) and 2. Control Unit (CU)

1. Arithmetic Logic Unit (ALU)


 It performs all arithmetic calculations and take logical decision.
 It can compare, count, shift or other logical activities.
 All such calculation and comparisons are done in this unit and return information
(Output) to the memory unit if storage require.
 It calculates very fast.

2. Control Unit (CU)


 It manages and coordinates operations of all other components of computer system.
 It retrieve instruction or data from memory.
 It decode instruction.
 It coordinate time sequence of instruction among various components of system.
 It determine requirement of storage and take action according to it.
Memory Unit
The storage unit of computer system store data for following purposes.
 Processing data and instructions
 Storage of temporary result (Intermediate data storage)
 Permanent storage for future requirement (Secondary Storage)
There are two types of Storage
1. Primary Storage
2. Secondary or Auxiliary Storage

1. Primary Storage (RAM)


 Store current Program or data (Running Program)
 It also store temporary data of current program
 Less space in comparison of secondary storage
 Volatile (Data Losses on power off)
 Comparatively more expensive
 Fast in operation

2. Secondary or Auxiliary Storage


 Used to store data and program for future usage.
 Large capacity (GBs) in comparison with primary memory.
 Slower than primary memory
 Retain data without power
 Cheaper than primary memory
 Example: Hard Disk Drive (HDD), Floppy Disk, CD/DVD, Pen Drive, Memory Card etc.
Input and Output Unit
 Basic aim of I/O devices is to provide communication between computer and user.
 Input device transmit the data as a series of electrical pulses into computer memory unit
where it will be available for processing.

 Some input devices, such as the keyboard, enable the user to communicate directly with
the machine.
Output Devices:
 Output device supply result of processing from primary storage or secondary storage.
 When a program executed and the results must be available in a human readable form.
 The output devices translate processed data from a machine coded form to a form that can
be read and used by people.
 Most common types of output devices are monitor which resembles a screen, printer prints
copy from computer on paper, plotter plot diagram or figure on paper.
2. Enlist types of operators and explain any two in detail with example.
Operators help in doing various operations. The operator can be divided into different
categories as shown below.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Increment and Decrement Operators
6. Conditional Operators
7. Bitwise Operators
8. Special Operators

Arithmetic Operators
 They are used to perform arithmetic operations.
 ‘C’ language supports following arithmetic operators.

 Except % operator all arithmetic operators can be used with any type of numeric operands,
while % operator can only be used with integer data type only.
Example: Program illustrating use of arithmetic operators.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf(“Enter the value of x and y:”);
scanf(“%d %d”,&x, &y);
printf(“\nAddition of x and y is: %d\n”, x+y);
printf(“Addition of x and y is: %d\n”, x-y);
printf(“Addition of x and y is: %d\n”, x*y);
printf(“Addition of x and y is: %d\n”, x/y);
printf(“Addition of x and y is: %d\n”, x%y);
}
Note: After every program write output of your code.
Output : ??

Relational Operators
 Relational operators are used to compare variables or constants.
 Relational operators are used to compare whether some variable value is higher (greater),
equal or lower with other variables.
 Following operators are the relational operators in ‘C’ language.

 Relational operators can be used in an expression.


 The operands of relational operators can be constants, variables or expressions.
 The relational expression will have value either true (1) or False (0).
Example
a=2, b=3, and c=5, d=3 then,
a < b (true) 2 < 3
5 > 3 (true)
4 < 8 (true)
a > 5 (false) 2 > 5
b < (a + c) (true) 3 < (2+5) = 3 < 7
Logical Operators
 Sometime we need to take certain action if some conditions are true or false.
 Logical operator help us to combine more than one condition, and based on the outcome
certain steps are taken.

 Logical NOT is an unary operator.


 We can use more than one logical operator in an expression.
 ! (NOT) is evaluated first, then && (AND) and the || (OR).
Assignment Operators
 It is used to assign a value to a variable.
 Syntax: variable = value/expression/variable.
 ‘C’ language also supports shorthand notation.
 Example a=a+5 can also be written as a +=5 and b=b+7 can also be written as b +=7

Increment and Decrement Operator


 Sometime we need to increase or decrease a variable by one.
 We can do that by using assignment operator ‘=’.
 Example a=a+1 increment value of variable a by 1 and a=a-1 decrement value of variable
a by 1.
 ‘C’ language provides special operators ++ (increment operator) and -- (decrement
operator) for doing this.
 This operator are unary.

Conditional Operator (Ternary Operator)


 ‘C’ language provides ‘?’ operator as a conditional operator.
 It is also known as a ternary operator.
 Syntax: expr1 ? expr2 : expr3;
Here, expr1 is logical expression. This logical expression can be TRUE or FALSE.
Expr2 and expr3 are expressions.
 Expr1 will evaluated first, and depending on its value TRUE or FALSE, either expr2 or
expr3 is evaluated.
 If expr1 is true then expr2 is executer, otherwise expr3 is executed.
 Use of ternary operator is an alternative use of if..else statement.
Example: Write a program to find maximum and minimum of two numbers using Ternary (?:)
Operator
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,max,min;
clrscr();
printf(“Enter the value of X & Y\n”);
scanf(“%d %d”,&x,&y);
max=(x>y) ? x : y ;
min=(x<y) ? x : y ;
printf(“Maximum number is:%d”, max);
printf(“Minimum number is:%d”, min);
getch();
}
Output
Bitwise Operator
 ‘C’ language supports some operators which can perform at the bit level.
 This type of operations are normally done in assembly or machine level programing.
 But in ‘C’ language support bit level manipulation also that is why ‘C’ language is also
known as middle-level programming language.
Other Special Operators
 Comma Operator, sizeof operator, arrow(->) operator, dot(.) operator, * operator and &
operator are special operator used in c language.
 arrow(->) operator, dot(.) operator are member selection operators used with a data
structure called as structure.
 * operator and & operator are normally used with pointer.
Comma Operator (,)
 It is used to combine multiple statements.
 It is used to separate multiple expression.
 It has lowest precedence.
 It is mainly used in for loop.
 The expression which are separated by comma operator are evaluated from left to right.
 Associativity of comma operator is from left to right.
sizeof Operator
 sizeof operator is used to find out the storage requirement of an operand in memory.
 It is an unary operator which returns the size in bytes. For Example,
sizeof(float) returns the value 4
sizeof(int) returns the value 2
sizeof(char) returns the value 1
also,
char c;
sizeof(c);
will return the value 1, because c is character type variable, and character requires one byte
of storage.
3. Explain putchar(), puts(), getchar(), getch(), getche(), scanf(), printf() functions with
suitable example
getchar( ):
It reads a single character from input device.
putchar():
It displays or writes a single character to the standard output device or screen. This function is
defined in <stdio.h> header file.
#include<stdio.h>
void main()
{
char x;
x=getchar(); //this will get a single character from user from keyboard
putchar(x); //this will print a single character to output screen
}
getch():
This function is used to read a character from the console but does not echo to the screen.
getche():
getche( ) function is used to read a character from the console and echoes that character to the
screen.
gets():
gets() function accepts single or multiple characters of string including spaces from the
standard input device until ENTER key is pressed.
puts():
puts() function displays or writes a string to the standard output device. It appends a newline
character to string.
printf() Function:
It is a formatted output function. The printf() function is used to print the data in specified
format onto a standard output device. This function can operate on any of the built-in data
types. It can be used to output any combination of numerical values, single character and
strings.
scanf() Function:
The scanf() function reads data from the input device and stores them at the given memory
location.
It can handle any built-in type and strings. The function is included in <stdio.h> file.
Difference between

4. What is Algorithm and Flowchart? Enlist various symbols used in Flowchart


Algorithm can be defined as: “A sequence of activities (steps) to be processed for getting
desired output from a given input.
Example : Find the area of a Circle of radius r.
Algorithm:
Step1: Read\input the Radius r of the Circle
Step2: Area PI*r*r // calculation of area
Step3: Print Area
Flowchart
 A flowchart is a pictorial representation of an algorithm.
 It represents solution in form of picture, it is easier to understand and develop.
 Symbol Used in Flow Chart

Example: Flow chart for finding maximum out of three numbers.


5. Differentiated between Hardware and Software. What is system software?

System Software
 System software is designed to control operation and extend the processing capabilities of
computer system.
 They control internal computer functions, such as reading data from input device, transmit
processing information to output devices, provide various facilities like file management,
Input/output management and CPU time to user program during execution of program.
 They help hardware component to work together and provide support for development and
execution of application software.
 There are various system software available.
1. Operating System (OS)
2. Compiler
3. Assembler
4. Loader
5. Linker
6. Editor
7. Translator
8. Macro Processor
9. Interpreters
6. Describe following string functions in C – Language.
(1) strcpy( ) , (2) strcat( ) , (3) strlen( ) , (4) strcmp ( )
 strlen() function
strlen() is used to return the length of the string , that means counts the number of characters
present in a string.
Syntax
integer variable = strlen (string variable);

 strcat() function
The strcat() is used to concatenate two strings. The second string will be appended to the end
of the first string. This process is called concatenation.
Syntax
strcat (StringVariable1, StringVariable 2);

 strcmp() function
strcmp() function is used to compare two strings. strcmp() function does a case sensitive
comparison between two strings. The two strings are compared character by character until
there is a mismatch or end of one of the strings is reached (whichever occurs first). If the two
strings are identical, strcmp( ) returns a value zero. If they‟re not, it returns the numeric
difference between the ASCII values of the first non-matching pairs of characters.
Syntax
strcmp(StringVariable1, StringVariable2);

 strcpy() function:
strcpy() function is used to copy one string to another. strcpy() function copy the contents of
second string to first string.
Syntax
strcpy(StringVariable1, StringVariable2);
7. What is array? Give example and advantages of array. Explain initialization of an
array value by example.
An array is collection of variable having same data type.
An array permits homogeneous data. It means that similar types of elements are stored
contiguously in the memory under one variable name.
Suppose we have to store the roll numbers of the 100 students the we have to declare 100
variables named as roll1, roll2, roll3, …, roll100 which is very difficult job. C programming
arrays is introduced in C which gives the capability to store the 100 roll numbers in the
contiguous memory which has 100 blocks and which can be accessed by single variable name.
Syntax: <data type> array name [size1][size2].....[sizen]
Examples for initialization:
int iarr[3] = {2, 3, 4};
char carr[20] = “program”;
float farr[3] = {12.5, 13.5, 14.5};

8. Define following terms:


Keywords:
Keywords are words whose meaning is fixed and is known by compiler.
 You cannot use fixed keyword as other purpose. i.e. not for function/variable name
 Keywords are also known as reserved words.
 Keyword must be in second alphabet.
 There are 32 keywords in C language.
Identifiers:
 These are the words which are defined by the programmer in a program.
 Identifier can be the variables, symbolic constant, functions etc.
 The name of identifiers should be meaningful so that the maintenance of the program
becomes easy
 Following are rules for naming an identifier
o The first character must be alphabet or underscore ( _ )
o Reserved words i.e. keywords cannot be used as identifiers.
o Identifier names are case sensitive, i.e. name and Name are treated as different
identifiers.
Machine Language:
 In this language programs are written in 0’s and 1’s forms (Binary Language).
 This languages are directly understandable to computer system.
 Every CPU has its own machine language.
Advantage
 Program Execution is faster in comparison with any other type of Language.
 Due to direct writing in to machine code, Size of code is small and compact.
 It occupy less memory.
Disadvantage
 Very deep technical knowledge is require to run the program.
 Binary language is difficult to understand.
Compiler:
It translate higher level program to machine level program.
Assembly Language:
 It is also classified as low-level language.
 This language mnemonic in place of 0’s and 1’s to represent codes.
 It use symbolic addressing capabilities.
Advantage
 Symbolic presentation make easy to write and understand the program.
Disadvantage
 Coding in this language is somewhat time consuming.
 Assembly language depended on machine type.
 They are designed for specific company and model of processor used.
Interpreter:
It translate line by line high level programs into low level programs.
9. Explain how string is defined in C. List the various inbuilt string functions
 A string is a sequence of character enclosed with in double quotes (“ ”) but ends with
\0(null).
 The compiler puts \0 at the end of string to specify the end of the string.
To get a value of string variable we can use the two different types of formats.
 String is defined as follow
char name[100];
List of in-built string functions

10. Enlist branching statements with suitable example. For loop, do while loop, while loop
with syntax.
The statements that help us to execute set of statements repeatedly are called as looping
statements.
There are 3 loops
1. For Loop
2. do..While loop
3. While Loop
While Loop
The while statement is typically used in situations where it is not known in advance
how many iterations are required.
Syntax:
while ( control expression )
{
An action or Series of Actions ; //body of loop
}
Here, first the control expression is evaluated to TRUE or FALSE. If it is evaluated to
TRUE, then an action or series of action i.e. body of loop is executed. The process of executing
the body of loop is repeated until the control expression is FALSE. Once control expression is
evaluated to FALSE, then the control is transferred out of the loop. The execution resumes
from the statement following the loop (if any).
Generally, when initialization and updating is included in the while loop, it looks as follows.
Initialization // initialization is used before the start of loop and sets
// the variable(s) to control the loop
while ( control expression )
{
An action or Series of Actions ; //body of loop
}
Flowchart:

for statement
The for statement is most often used in situations where the programmer knows in advance
how many times a particular set of statements are to be repeated. The for statement is
sometimes termed as counter controlled loop.
Syntax :
for ( expression1 ; expression2 ; expression3 )
{
An action or series of actions ; // body of loop
}
expression1:- This is usually an assignment/initialization statement to set a loop control
variable(s) for example. But it is not restricted to only initialization, it can be any valid C
statement.
expression2:- This is usually a control expression which determines when loop will
terminate. But, this can be any statement of C that evaluates to TRUE or FALSE.
expression3:- This usually defines how the loop control variable(s) will change each time the
loop is executed i.e. updating.
Body of loop:- Can be a single statement, no statement or a block of statements.

do…while statement
The terminating condition in the for and while loops is always tested before the body of the
loop is executed -- so of course the body of the loop may not be executed at all.
In the do…while statement on the other hand the body of the loop is always executed at least
once as the condition is tested at the end of the body of the loop.

Syntax :
Initialization
do
{
//body of the loop
} while (control expression ) ;
The flowchart of do…while loop is shown below
11. Explain the use of following statements.
(I) break (II) continue (III) goto

goto
The goto statement is known as jump statement in C. As the name suggests, goto is used to
transfer the program control to a predefined label. The goto statment can be used to repeat
some part of the code for a particular condition.
12. List out basic data types in C with its Memory size

13. Explain Entry controlled loop and Exit controlled loop with appropriate flow chart.

Flow chart
14. Show 1D array, 2D array declaration, initialization and iteration
Single / One Dimensional Array:
1. Single or One Dimensional array is used to represent and store data in a linear form.
2. Array having only one subscript variable is called One-Dimensional array
3. It is also called as Single Dimensional Array or Linear Array
Single Dimensional Array Declaration and initialization:
Syntax for declaration: <data type> <array name> [size];
Examples for declaration: int iarr[3]; char carr[20]; float farr[3];
Examples for initialization:
int iarr[3] ;
char carr[20] = “program”;
float farr[3] = {12.5, 13.5, 14.5}
You can enter elements using for loop (From Keyboard)
for (i=0;i<5;i++)
{
scanf(“%d”, &num[i]);
}

Two Dimensional (2D)Arrays:


1. Two Dimensional Array requires Two Subscript Variables
2. Two Dimensional Array stores the values in the form of matrix.
3. One Subscript Variable denotes the “Row” of a matrix.
4. Another Subscript Variable denotes the “Column” of a matrix
Syntax: <data type> <array name> [row subscript][column subscript];
Example:
Declaration: Char name[50][20];
Initialization:
int a[3][3] = { 1, 2, 3
4, 5, 6,
7, 8, 9}

15. What is conditional statement? Describe If, else If, nested Else If, Else if ladder and
switch case statement with example.
There come situations in real life when we need to make some decisions and based on these
decisions, we decide what we should do next. Similar situations arise in programming also
where we need to make some decisions and based on these decisions we will execute the next
block of code.
Decision making statements in programming languages decides the direction of flow of
program execution. Decision making statements available in C are:
1. if statement
2. if..else statements
3. nested if statements
4. if-else-if ladder
5. switch statements
if statement in C
if statement is the most simple decision making statement. It is used to decide whether a certain
statement or block of statements will be executed or not i.e if a certain condition is true then a
block of statement is executed otherwise not.
Syntax:
if(condition)
{
// Statements to execute if condition is true
}
Here, condition after evaluation will be either true or false. C if statement accepts boolean
values – if the value is true then it will execute the block of statements below it otherwise not.
If we do not provide the curly braces ‘{‘ and ‘}’ after if(condition) then by default if statement
will consider the first immediately below statement to be inside its block.

Example
#include <stdio.h>
void main()
{
int i = 10;
if (i > 15)
{
printf("10 is less than 15");
}
printf("I am Not in if");
}
Output:
I am Not in if
if-else in C
The if statement alone tells us that if a condition is true it will execute a block of statements
and if the condition is false it won’t. But what if we want to do something else if the condition
is false. Here comes theC else statement. We can use the else statement with if statement to
execute a block of code when the condition is false.
Syntax:
if (condition)
{
// Executes this block if condition is true
}
else
{
// Executes this block if // condition is false
}
Example
#include <stdio.h>
void main()
{
int i = 20;
if (i < 15)
{
printf("i is smaller than 15");
}
else
{
printf("i is greater than 15");
}
}
Output:
i is greater than 15
nested-if in C
A nested if in C is an if statement that is the target of another if statement. Nested if statements
means an if statement inside another if statement. C allows us to nested if statements within if
statements, i.e, we can place an if statement inside another if statement.
Syntax:
if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
}
Example:
#include <stdio.h>
void main()
{
int i = 10;
if (i == 10)
{
// First if statement
if (i < 15)
{
printf("i is smaller than 15\n");
// Will only be executed if statement above is true
}
if (i < 12)
{
printf("i is smaller than 12 too\n");
}
else
{
printf("i is greater than 15");
}
}
}
Output:
i is smaller than 15
i is smaller than 12 too
if-else-if ladder in C
Here, a user can decide among multiple options. The C if statements are executed from the
top down. As soon as one of the conditions controlling the if is true, the statement associated
with that if is executed, and the rest of the C else-if ladder is bypassed. If none of the
conditions are true, then the final else statement will be executed.
Syntax:
if (condition)
statement;
else if (condition)
statement;
..
else
statement;
Example:
#include <stdio.h>
void main()
{
int i = 20;
if (i == 10)
printf("i is 10");
else if (i == 15)
printf("i is 15");
else if (i == 20)
printf("i is 20");
else
printf("i is not present");
}
Output:
i is 20
switch case in c
The switch statement allows us to execute one code block among many alternatives.
You can do the same thing with the if...else..if ladder. However, the syntax of the switch
statement is much easier to read and write.
Syntax
switch (expression)
{
case constant1:
// statements
break;
case constant2:
// statements
break;

default:
// default statements
}
The expression is evaluated once and compared with the values of each case label.
If there is a match, the corresponding statements after the matching label are executed. For
example, if the value of the expression is equal to constant2, statements after case constant2:
are executed until break is encountered.
If there is no match, the default statements are executed.
Example
#include <stdio.h>
void main()
{
char operation;
double n1, n2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operation);
printf("Enter two operands: ");
scanf("%lf %lf",&n1, &n2);
switch(operation)
{
case '+':
printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
break;
default:
printf("Error! operator is not correct");
}
}
16. Explain the concept of Pointers. What is Array of Pointers?
A pointer is a variable whose value is the address of another variable, i.e., direct address of
the memory location. Like any variable or constant, you must declare a pointer before using it
to store any variable address.
Syntax
data_type *var-name;
The asterisk * used to declare a pointer
int *ip; /* pointer to an integer */
Example
#include <stdio.h>
int main ()
{
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var; /* store address of var in pointer variable*/
printf("Address of var variable: %x\n", &var ); /* address stored in pointer variable */
printf("Address stored in ip variable: %x\n", ip ); /* access the value using the pointer */
printf("Value of *ip variable: %d\n", *ip );
return 0;
}
Output:
Address of var variable: bffd8b3c
Address stored in ip variable: bffd8b3c
Value of *ip variable: 20
Array of pointers
There may be a situation when we want to maintain an array, which can store pointers to an int
or char or any other data type available. Following is the declaration of an array of pointers.
int *ptr[MAX];
It declares ptr as an array of MAX integer pointers. Thus, each element in ptr, holds a pointer
to an int value.
Example
#include <stdio.h>
const int MAX = 3;
void main ()
{
int var[] = {10, 100, 200};
int i, *ptr[MAX];
for ( i = 0; i < MAX; i++)
{
ptr[i] = &var[i]; /* assign the address of integer. */
}
for ( i = 0; i < MAX; i++)
{
printf("Value of var[%d] = %d\n", i, *ptr[i] );
}
}
When the above code is compiled and executed, it produces the following result −
Value of var[0] = 10
Value of var[1] = 100
Value of var[2] = 200

17. Give a difference between User-Define function and Library Function.


18. List out category of functions
Ans:
1. Function without arguments (parameters) and without a return value.
e.g. void main()
It specifies that the function does not receive any arguments and does not return any value
to the main() function

2. Function with arguments and without a return value.


void largest(int x, int y)
It specifies that the function receives two integer arguments from the calling function and
does not return any value to the called function.

3. Function without arguments and with a return value.


int sum()
It specifies that the function does not receive any arguments but returns a Integer value to
the calling function.

4. Function with arguments and with a return value.


int largest(int x, int y, int z)
It specifies that the function receives three values and returns a value to the calling
function.

19. Difference between Local variables and Global variables.


20. Difference between call by value and Call by reference

21. Explain Recursion.


The process in which a function calls itself directly or indirectly is called recursion and the
corresponding function is called as recursive function.
In the recursive program, the solution to the base case is provided and the solution of the
bigger problem is expressed in terms of smaller problems.
int fact(int n)
{
if (n < = 1) // base case
return 1;
else
return n*fact(n-1);
}
In the above example, base case for n < = 1 is defined and larger value of number can be
solved by converting to smaller one till base case is reached.
Difference between Iterative Function and Recursive function
Example of Iteration
We can solve above program of finding factorial using Iteration.
void main()
{
int i,fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf(“Factorial=%d”,fact);
}

22. List out storages classes of variable


Ans:

Storage classes in C are used to determine the lifetime, visibility, memory location, and
initial value of a variable. There are four types of storage classes in C
o Automatic
o External
o Static
o Register

Note: Please refer book or Internet for the description and example if it is ask in exam having
7 marks.
23. Give difference between Structure and Union.

Note: Please refer book or Internet for the description and example if it is ask in exam having
7 marks.
24. What is Dynamic Allocation? List out memory allocation functions.
An array is a collection of a fixed number of values. Once the size of an array is declared, you
cannot change it.
int a[10];
If there is a situation where only 5 elements are needed to be entered in this array. In this case,
the remaining 5 indices are just wasting memory in this array. So there is a requirement to
lessen the length (size) of the array from 10 to 5.
Take another situation. In this, there is an array of 10 elements with all 10 indices filled. But
there is a need to enter 3 more elements in this array. In this case, 3 indices more are required.
So the length (size) of the array needs to be changed from 10 to 13.
To solve this issue, you can allocate memory manually during run-time. This is known as
dynamic memory allocation in C programming. To allocate memory dynamically, library
functions are malloc(), calloc(), realloc() and free() are used. These functions are defined in
the <stdlib.h> header file.
malloc() method: memory allocation
The “malloc” or “memory allocation” method in C is used to dynamically allocate a single
large block of memory with the specified size. It returns a pointer of type void which can be
cast into a pointer of any form. It doesn’t initialize memory at execution time so that it has
initialized each block with the default garbage value initially.
Syntax:
ptr = (type *) malloc(byte-size)
Example:
ptr = (int*) malloc(100 * sizeof(int));
Since the size of int is 2 bytes, this statement will allocate 200 bytes of memory. And, the
pointer ptr holds the address of the first byte in the allocated memory.
calloc() method: contiguous allocation
“calloc” or “contiguous allocation” method in C is used to dynamically allocate the specified
number of blocks of memory of the specified type. It is very much similar to malloc() but has
two different points and these are:
It initializes each block with a default value ‘0’.
It has two parameters or arguments as compare to malloc().
Syntax:
ptr = (type*)calloc(n, element-size);
Here, n is the no. of elements and element-size is the size of each element.
For Example:
ptr = (float*) calloc(25, sizeof(float));
This statement allocates contiguous space in memory for 25 elements each with the size of the
float.

free() method
“free” method in C is used to dynamically de-allocate the memory. The memory allocated
using functions malloc() and calloc() is not de-allocated on their own. Hence the free() method
is used, whenever the dynamic memory allocation takes place. It helps to reduce wastage of
memory by freeing it.
Syntax:
free(ptr);
realloc() method
“realloc” or “re-allocation” method in C is used to dynamically change the memory allocation
of a previously allocated memory. In other words, if the memory previously allocated with the
help of malloc or calloc is insufficient, realloc can be used to dynamically re-allocate memory.
re-allocation of memory maintains the already present value and new blocks will be initialized
with the default garbage value.
Syntax:
ptr = realloc(ptr, newSize);
Where, ptr is reallocated with new size 'newSize'
25. List out various mode of File open. Also discuss File Function.
File handling in C enables us to create, update, read, and delete the files stored on the local file
system through our C program. The following operations can be performed on a file.

 Creation of the new file


 Opening an existing file
 Reading from the file
 Writing to the file
 Deleting the file

You might also like