Professional Documents
Culture Documents
Unit 2
Unit 2
Unit 2
2 MARKS
Compiler: It is a program which is used to convert the high level language program into
machine language.
Assembler: It is a program which is used to convert the assembly level language program into
machine language.
Interpreter: It is a program; it takes one statement of a high level language program, translates it
into machine language instruction and then immediately executes the resulting machine language
instruction.
2.What is a linker?
S No Compiler Interpreter
Executes Source Code Into Target Executes Source Code Directly Or To
1 Or An
Assembly Code. Intermediate Form.
Compilers Convert Once The
2 Source Interpreter Converts Every Time The
Program. Program Runs.
Languages For Compiler Languages For Interpreter
3 Conversion: C, Conversion:
The variables that are used in more than one function throughout the program are called global
variables and declared outside of all the function that is before main().
The character set is a fundamental raw material of any language and they are used to
represent information like natural languages, computer language will also have well defined
character set, which is used to built the programs.
The programs are usually referred as individual text and punctuation in a passage of text.
The C language program can contain the individual units called C tokens
Data type is the type of the data that are going to access within the program. C supports
different data types each data type may have pre-defined memory requirement and storage
representation.
Keywords are certain reserved words that have standard and pre-defined meaning in
‘C’. These keywords can be used only for their intended purpose.
The items whose value cannot be changed during a execution of a program are called
constants.
Integer constant: Integer constant formed with the sequence of digits. There are three type of
integer constants which forms different number system
Real constant: Real constant is made up of a sequence of numeric digits with presence of
decimal point. It serves as a good purpose to represent quantities that vary continuously such as
distance, height, temperature etc.
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Conditional operators ( Ternary operator )
Bit wise operators
Special operators
The data items that operators act upon are called operands.
Example: a+b; In this statement a and b are called operands.
If the exp1 is true variable takes value of exp2. If the exp2 is false, variable takes the
value of exp3.
Example: k=~j; where ~ take one’s complement of j and the result is stored in k.
AND (&)
Only used in Bitwise manipulation. It is a unary operator.
Example:
int x,y;
c = (float) x/y;
where a and y are defined as integers. Then the result of x/y is converted into float.
The conversion specifications are used to accept or display the data using the
INPUT/OUTPUT statements.
if while
(i) It is a conditional statement (i) It is a loop control statement
(ii) If the condition is true, it executes (ii) Executes the statements within the
some statements. while block if the condition is true.
(iii) If the condition is false the control is
(iii) If the condition is false then it stops
transferred to the next statement of the
the execution the statements.
loop.
23 What is the difference between while loop and do…while loop?
In the while loop the condition is first executed. If the condition is true then it
executes the body of the loop. When the condition is false it comes of the loop. In the do…
while loop first the statement is executed and then the condition is checked. The do…while
loop will execute at least one time even though the condition is false at the very first time.
25. How many bytes are occupied by the int, char, float, long int and double?
int - 2 Bytes
char - 1 Byte
float - 4 Bytes
long int - 4 Bytes
double - 8 Bytes
++a means do the increment before the operation (pre increment) a++ means do the
increment after the operation (post increment)
Example:
a=5;
x=a++; /* assign x=5*/
y=a; /*now y assigns y=6*/
x=++a; /*assigns x=7*/
28. What is a String?
The global variable is a variable that is declared outside of all the functions. The
global variable is stored in memory, the default value is zero. Scope of this variable is
available in all the functions. Life as long as the program’s execution doesn’t come to an end.
\n - New Line
\b - Backspace
\t - Form feed
\’ - Single quote
\\ - Backspace
\t - Tab
\r - Carriage return
\a - Alert
\” - Double quotes
while (1)
{
}
Here 1 is a non zero, value so the condition is always true. So it is an infinite loop.
32. Write the limitations of getchar( ) and scanf( ) functions for reading strings
(JAN 2009)
getchar( )
To read a single character from stdin, then getchar() is the appropriate.
scanf( )
scanf( ) allows to read more than just a single character at a time.
The getch ( ) function is written in standard I/O library. It reads a single character
from a standard input device. This function does not require any arguments, through a pair of
empty parenthesis, must follow the statement getch ( ).
In scanf() when there is a blank was typed, the scanf() assumes that it is an end.
gets() assumes the enter key as end. That is gets() gets a new line (\n) terminated string of
characters from the keyboard and replaces the ‘\n’ with ‘\0’.
The putchar ( ) function is used to display one character at a time on the standard output
device. This function does the reverse operation of a single character input function.
Syntax: if(expression)
statements;
The loop is defined as the block of statements which are repeatedly executed for certain
number of times.
It is basically two way decision-making statement and always used in conjunction with
condition. It is used to control the flow of execution and also used to carry out the logical test
and then pick up one of the two possible actions depending on the logical test.
Syntax: if(expression)
statements;
else
statements;
The for loop is another repetitive control structure and is used to execute set of
instructions repeatedly until the condition becomes false.
40. What are the differences between while and dowhile loop?
While dowhile
The condition is first tested if the It executes the body once after it check the
condition is true then the block is executed conditions if it is true the body of the loop is
until the condition becomes false. executed until the condition become false.
Loop will not be executed if the condition Loop is executed atleast once
is false. even though the condition is false.
The switch statement is used to pick up or execute a particular group of statements from
several available group of statements. It allows us to make a decision from the number of
choices.
The loop within the loop is called nested loop. In nested for loop one or more for
statements are included in the body of the loop. The number of iterations in this type of
structures will be equal to the number of iterations in the outer loop multiplied by the number of
iterations in the inner loop.
The goto statement transfer control unconditionally from one place to another place in the
program.
If we want to take the control to the beginning of the loop by passing the statements
inside the loop which have not yet been executed, for this purpose the continue is used. When the
statement continue is encountered inside any C loop control automatically passes to the
beginning of the loop
16 MARKS