Sei sulla pagina 1di 9

SRM UNIVERSITY

Ramapuram, Chennai.
Department of Computer Applications
UCA15102- Programming in C
Question Bank
Unit I
Part A 2 Marks
1. Define: Constants. Mention its types
The value assigned for the variable is called constant. It cannot change at
runtime. Ex: float pi = 3.14;
Numeric Constant – Integer Constant, Real Constant
Character Constant – Character Constant, String Constant
2. Define: Variables.
The memory location of the value is called variable. It can change at
runtime. Ex: int a;
3. Define: Keywords.
There are certain reserved words in C is called keywords, they have
standard, predefined meaning in C programming language. These keywords can
be used only for their intended purpose; they cannot be used as programmer
defined identifiers.
4. What is character set?
A set of symbols, digits and alphabets are called character set. By this
character set only, programmer can create a program. Ex: digits: 0 to 9, alphabets:
a – z (both lowercase and uppercase) and special symbols (&, $, #, @, etc).
5. What is symbolic constant?
A symbolic constant is a name that substitutes for a sequence of characters. The
character may represent a numeric, a character or a string constant.
Ex: # define TRUE 1
6. Write the I/O functions in C.
The scanf( ) and printf( ) are the basic I/O functions in C. The getchar(),
putchar(), gets(), and puts() are also the I/O functions.
7. What is an identifier?

1
Identifiers are names that are given to various program elements, such as
variables, functions and arrays. It consists of letters and digits, identifier
must start with alphabet. Special symbols are not allowed except
underscore( _ ).
8. Write the rules to define an identifier.
 Identifiers must begin with letter.
 It should not be a keyword.
 Special symbols not allowed except underscore ( _ ).
9. What are the data types available in C?
 int – integer quantity (2 bytes, it varies from one compiler to another)
 float – floating point number (4 bytes)
 double – double precision floating point number ( 8 bytes)
 char – single character ( 1 byte)
 Note: There is no special data type for string. The char type is used to
define a string.
10. List the rule for naming a variable in C.

 Every variable name should start with alphabets or underscore (_).


 No spaces are allowed in variable declaration.
 Except underscore (_) no other special symbol are allowed in the
middle of the variable declaration (not allowed -> roll-no, allowed ->
roll_no).
 Maximum length of variable is 8 characters depend on compiler and
operation system.
 Every variable name always should exist in the left hand side of
assignment operator (invalid -> 10=a; valid -> a=10;).
 No keyword should access variable name (int for <- invalid because for
is keyword).

11. Define statements.


A statement causes the computer to carry out some action. There are three
different classes of statements in C.
a) Expression statement b) compound statement c) control statement.
12. What are the primary data types in C?
The primary datatypes of C is int, float and char, depending upon the requirement
of the programmers they will extend.

2
13. How to declare a variable as constant.

ANSI C allows you to declare constants. When you declare a constant it is a bit


like a variable declaration except the value cannot be changed.

The const keyword is to declare a constant, as shown below:


int const a=1;
const int a=2;

14. What is compound statement?


A compound statement consists of several individual statements enclosed within a
pair of braces { }.
15. Writ a short note on History of C.
C was originally developed in the 1970s by Dennis Ritchie at Bell Telephone
Laboratories. It is an outgrowth of two earlier languages, called BCPL and B. C
was largely confined to use within Bell laboratories until 1978. In 1980, C had
numerous compilers and interpreters for future development.
16. List the features of C.
C programming has some unique features
 Arrays, structure and union
 Storage classes
 Pointers
 File handling concepts

17. What is compiler? Which compiler is used in your lab?


The compiler is the system software; it is used to develop programs in C. There
several compilers available (TurboC, BorlandC, ANSI C, etc). In our lab, we are
using TurboC compiler.
18. Write the syntax of scanf( ) function.
Scanf (control string, arg1, arg2, arg3,…,argn)
Where control string refers to formatting information, and arg1, arg2, arg3,
…,argn are arguments that represent the individual input data items.
19. What is a unary operator?
A operator operates single operand is called unary operator. Ex: a++, b--, -c;
20. What is a Binary operator?

3
A operator operates two operands is called Binary operator. Ex: a+b;
21. What are operators available in C.
 Arithmetic operators ( +, -, *, /, % )
 Relational operators ( <, <=, >, >=, ==, !=)
 Logical operators ( &&, ||, !)
 Assignment operators ( =, +=, -=, etc)
 Bitwise operators ( &, | )
 Special operator (conditional operator or Ternary operators) ? and :
22. Describe library functions.
The predefined functions or built-in functions are called library functions. It is
also called intrinsic functions. These functions are carried out various commonly
used operations or calculations.
23. 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.
24. What is meant by Enumerated data type.
Enumerated data is a user defined data type in C language. Enumerated data type
variables can only assume values which have been previously declared.
Example :
enum month { jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec };
25. 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.
26. What do you meant by conditional or ternary operator?

? : If Condition is true ? Then value X : Otherwise value Y


27. What is the use of sizeof() operator in C.
Sizeof operator is used to return the size of an variable.
Example :sizeof(a), Where a integer, will return 4.

4
28. 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


29. Why header files are included in ‘C’ programming?
This section is used to include the function definitions used in the program. · Each
header file has ‘h’ extension and include using ’# include’ directive at the
beginning of a program.

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

Part B (16 Marks)


1. Explain the different Data types in C.
2. What is operator? Explain different types of Operators in C.
3. Explain library functions in C.
4. Discuss about all input and output statements in C with suitable
example.
5. Explain formatted and unformatted input/output statements in C with example.

Unit II
Part A 2 Marks

1. Define Looping in C .

5
A loop statement allows us to execute a statement or group of statements
multiple times and following is the general from of a loop statement in most of
the programming languages:

2. What are the types of looping statements available in C


C programming language provides following types of loop to handle looping
requirements.
Loop Type Description
Repeats a statement or group of
while statements while a given condition is true.
It tests the condition before executing the
loop body.
Execute a sequence of statements multiple
for loop times and abbreviates the code that
manages the loop variable.
Like a while statement, except that it
do...while tests the condition at the end of the loop
body
You can use one or more loop
nested loops inside any another while, for or
do..while loop.

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

6
some statements. while block if the condition is true.

(iii) If the condition is false then it stops (iii) If the condition is false the control is

the execution the statements. transferred to the next statement of the loop.

4. Define: Top tested loop and Bottom tested loop.


In the top tested loop, the condition is checked at the top or at the beginning.
Sometimes this loop is called entry controlled loop. Ex: while loop
In the Bottom tested loop, the condition is checked at the bottom or at the end.
Sometimes this loop is called exit controlled loop. Ex: do-while loop
5. What is a conditional statement?
This is a statement used to check the condition given by the user. There are four
conditional statements in C; if, if-else, nested if, and switch case statement.
6. Differentiate while and do-while loop.
While loop Do- while loop
The condition is checked at first The condition is checked at last
If the condition is false, the control is If the condition is false, even though
exit from the loop and the loop is not the loop is executed at least once then
executed further. the control is exit from the loop
There is no semicolon at the end of the There is a semicolon at the end of the
loop loop

7. Give the syntax for ”for” statement


For(initialization; condition test; increment or decrement)
{
//code – C statements to be repeated
}

8. Give the syntax for else-if ladder


if(Condition1)
{
/* Control will come inside only when the above condition1 is true*/
}

7
else if(Condition2)
{
/* Control will come inside only when the above condition2 is true*/
}
else if(Condition3)
{
/* Control will come inside only when the above condition3 is true*/
}
else
{
/* Control will come inside only when the above condition is true*/
}
9. What is the use of goto statement?
The goto statement is used to alter the normal sequence of program execution by
transferring control to some other part of the program. Syntax: goto label;
10. Compare Break and Continue statements
Break Continue
This statement is used to terminate This statement is used to bypass the
loops or to exit from a switch. remainder of the current pass through a
loop. The loop does not terminate when
a continue statement is encountered.
It can be used within a for, while, do- It can be used within a for, while, do-
while or switch statement. while loop statements.
Syntax: break; Syntax: continue;

11. What is nested loop?


A loop can be nested that is one loop nested within another.
12. Write the use of switch case statement.
The switch case statement is the alternative statement of nested if. It used to check
the condition one out of many.

Part B (16 Marks).


1. Explain the looping statement with suitable examples.
2. Briefly write about decision statement with examples.

8
3. Discuss about conditional statements with example.
4. With suitable program, explain about switch case.

Potrebbero piacerti anche