Unit 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

UNIT- II

2 MARKS

1. What are a Compiler, Assembler and Interpreter?

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?

A linker is a program that combines object modules to form an executable program.


Many programming languages allow you to write different pieces of code, called modules,
separately. This simplifies the programming task because you can break a large program into
small, more manageable pieces.
Modules has to be put together. This is the job of the linker.
In addition to combining modules, a linker also replaces symbolic addresses with real
addresses. Therefore, you may need to link a program even if it contains only one module.
3. Difference between Compiler and Interpreter. (JAN 2010)

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:

C++. MATLAB, Python.

4. What is meant by global declaration section?

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().

5. What is meant by C character set?

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.

6. What is meant C tokens?

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

7. Define data types?

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.

8. What are the different data types available in ‘C’?


There are four basic data types available in ‘C’.
1. int
2. float
3. char
4. double

9. What are Keywords?

Keywords are certain reserved words that have standard and pre-defined meaning in
‘C’. These keywords can be used only for their intended purpose.

10.Define constants? and What are the types of numeric constants?

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.

11. Define statements?

Statements can be defined as set of declaration or sequence of action. Statement causes


the computer to perform some

12. What are the types of operators?

 Arithmetic operators
 Relational operators
 Logical operators
 Assignment operators
 Increment and decrement operators
 Conditional operators ( Ternary operator )
 Bit wise operators
 Special operators

13. What is an Operator and Operand?

An operator is a symbol that specifies an operation to be performed on operands.


Example: *, +, -, / are called arithmetic operators.

The data items that operators act upon are called operands.
Example: a+b; In this statement a and b are called operands.

14. What is Ternary operators or Conditional operators?

Ternary operators is a conditional operator with symbols ? and :

Syntax: variable = exp1 ? exp2 : exp3

If the exp1 is true variable takes value of exp2. If the exp2 is false, variable takes the
value of exp3.

15 What are the Bitwise operators available in ‘C’?

& - Bitwise AND


| - Bitwise OR
~ - One’s Complement
>> - Right shift
<< - Left shift
^ - Bitwise XOR are called bit field operators

Example: k=~j; where ~ take one’s complement of j and the result is stored in k.

16 What are the logical operators available in ‘C’?

The logical operators available in ‘C’ are


&& - Logical AND
|| - Logical OR
! - Logical NOT

17 What is the difference between Logical AND and Bitwise AND?

Logical AND (&&)


Only used in conjunction with two expressions, to test more than one condition. If
both the conditions are true the returns 1. If false then return 0.

AND (&)
Only used in Bitwise manipulation. It is a unary operator.

18 What is the difference between ‘=’ and ‘==’ operator?

Where = is an assignment operator and == is a relational operator.


Example:
while (i=5) is an infinite loop because it is a non zero value and while (i==5) is true only
when i=5.

19 What is type casting?

Type casting is the process of converting the value of an expression to a


particular data type.

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.

20 What is conversion specification?

The conversion specifications are used to accept or display the data using the
INPUT/OUTPUT statements.

21 What is the difference between ‘a’ and “a”?

‘a’ is a character constant and “a” is a string.

22 What is the difference between if and while statement?

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.

24 . What is a Modulo Operator?

‘%’ is modulo operator. It gives the remainder of an integer division


Example:
a=17, b=6.
Then a%b gives 5.

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

26 What are the types of I/O statements available in ‘C’?

There are two types of I/O statements available in ‘C’.


Formatted I/O Statements
Unformatted I/O Statements

27. What is the difference between ++a and a++?

++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?

A string is a sequence of characters enclosed in a double quotes, the characters may


be letters , numbers , special characters and blank space etc, at the end of the string ‘ \0 ‘ is
automatically placed.

29. What is a global variable?

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.

30. What are the Escape Sequences present in ‘C’

\n - New Line
\b - Backspace
\t - Form feed
\’ - Single quote
\\ - Backspace
\t - Tab
\r - Carriage return
\a - Alert
\” - Double quotes

31. Construct an infinite loop using while?

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.

33. Define single character input getch ( ) function.

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 ( ).

34. What is the difference between scanf() and gets() function?

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’.

35.. Define single character output putchar ( ) function.

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.

36. Define simple if statement?

The if statement is a decision making statement. It is used to control the flow of


execution of the statements and also used to test logically whether the condition is true or false.

Syntax: if(expression)

statements;

37. What is meant by looping?

The loop is defined as the block of statements which are repeatedly executed for certain
number of times.

38. Define if-else statement?

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;

39. Define for loop?

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

This is top tested loop This is the bottom tested loop

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.

41. What is meant by switch statement

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.

42. Define nested for loop?

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.

43. What is meant by break statement?


The break statement is used to terminate the loop when the keyword break is used inside
any c loop control automatically transferred to the first statement after the loop. Break is usually
associated with an if statement.

44. Define goto statement?

The goto statement transfer control unconditionally from one place to another place in the
program.

45. What is meant by continuous statement?

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

1. Basic structure of c programs


2. Explain in detail about the constants, variables, expressions and statements in ‘C’.
3. Discuss about the various data types in ‘C’.
4. Describe the various types of operators in ‘C’ language along with its priority.
5. Explain about the various decision making statements in ‘C’ language.
6. Explain about the various branching and looping statements in ‘C’ language.
7. Explain briefly about the input and output function in ‘C’.
8. Explain briefly about Managing Input and Output

You might also like