Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C Two Marks

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Define the term variable and constant.

Variable:
A variable is a data name that is used to store a value. A variable may take different
values at different times. A variable can be chosen by the programmer in a meaningful way.
So as to reflect its function or nature in the program.
Eg:
city college a1
Total_mark Name Avg
Constant:
A constant is a value that does not change during the program execution. A constant used in
C does not occupy memory.

2. What is an expression in C language?

Expression is defined as a combination of operand and operator to obtain some computation.


Operands represent variable or values and the operator tells what operation is to be
performed.

3. Specify the use of printf( ) and scanf( ) functions.

❖ The function scanf() is used for formatted input from the standard input and provides many
of the conversion facilities.

❖ It is used for formatted output to standard output device,( screen) . The format
specification contains string and the data to be output, as the arguments(parameter) to the
printf() function.

4. What is an unary operator? Give example.

The operators that act upon a single operand to produce a new value is known as
unary operator.
Eg: minus operator(-) ,Increment operator (++)

5. What are formal arguments?

The formal parameters are used to collect values or address from the calling function to a
function being called.

6. Define the term recursion.

A function may call another function. When a function calls itself, it is referred to as
recursive call the process is known as recursion. C provides very good facilities for recursion.

7. What are automatic variable?

Variables that used as a local variable inside any function. This is the default one.
Initial value of variable is garbage value without initialization.
8. What are bitwise operators?

The bitwise operator performs the operation on bits (i.e, bit by bit). Using the bitwise
operators we can set/ reset/ check any bit in the value of the variable.

9. Define the term pointer data type.

A pointer is a variable that represent the location (rather than the value) of a data item,
such as a variable or an array element. It is a variable that holds a memory address. This
address is the location of another variable or an array element in memory.

10. What are keywords? Give example.

Keywords have fixed meaning and these meaning cannot be changed. These keywords
can be used only for their intended purpose, they cannot be used as programmer-defined
identifiers.

The following are examples of few keywords are predefined by C


auto double int struct
break else if switch
case enum do while

11. What is meant by declaration?

❖ Declaration is to represent a variable


❖ Only variable name and its data type is represented in declaration.

12. Specify the syntax used for ‘for’ statement.

The for loop is entry controlled loop the provides a more concise loop control structure.
The general format of the loop is

for(intilialization;test-condition;increment/decrement)
{
Body of the loop;
}

13. Mention the use of ‘break’ and ‘continue’ statements.

❖ The break statement is used to terminate the loop containing it.


❖ The continue statement does not terminate the entire loop but is used to terminate the
current iteration of the loop.

14. What are function prototypes?

A function declaration is also called as function prototype consists of four parts.


∙ Function type(return type)
∙ Function name
∙ Parameter list
∙ Terminating semicolon.

15. What are library functions?

The function that are predefined and supplied along with the compiler are known as built in
functions. They are also known as library function.

16. Specify the role of static variables.

❖ If you declare within a function, It retains the value between function call.
❖ If it is declare a for a function name. It will be visible from other files if the function
declaration is as static.
❖ Static are global variables. By default we can use the global variables from outside files if
it is static global.

17. What is a string?

A string is a sequence of characters ending with NULL. It can be treated as a


one-dimensional array of character terminated by a NULL character.

18. How to declare multidimensional array?

Two dimensional array follows row major order storage representation. The elements are
stored in row by row in the subsequent memory locations.

19. What is recursive function? Give an example.

Recursive function is a function which contains a call to itself.


Eg:
int factorial(int n)
{
if(n==0)
return(1);
else
return(n*factorial(n-1));
}

20. Define an array.

❖ Array is the collection of elements.


❖ Collection of the elements of the same data type.
❖ All elements are stored in the contiguous memory locations.

21. List any four bitwise operators.


Operator Meaning
& Bitwise AND
| Bitwise OR
<< Shift left
>> Shift right

21. What are Relational Operator in C?

The relational operators are used to compare arithmetic, logical and character expressions.
We often compare two similar quantities and depending on their relation, take some
decisions. Each of these operator compares their left hand side with their right hand side. The
whole expression involving the relational operator then evaluates to an integer. It evaluates to
zero if the condition is false, and one if it is true
Operator Meaning
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to

22. What is the purpose of conditional operator?

The conditional operator consists of two symbols the question mark (?) and the colon (:).
The conditional expression of the form
variable = exp1?exp2:exp3;
conditional expression

where exp1 is test expression, exp2 is expression or constant or variable, exp3 is expression
or constant or variable.

23. Write the advantages of pointer.

Pointer is used in the following cases.


∙ It is used to access array elements.
∙ It is used for dynamic memory allocation.
∙ It is used in call by reference.
∙ It is used in data structure like trees, graph, etc.

24. What is character set?

The C Character set consists of upper and lower case alphabets, digits, special character and
white spaces. The alphabet and digits are together called the alphanumeric characters.
∙ Alphabets:
A,B,C,D,E………………………X,Y,Z
a,b,c,d,e………………………..x,y,z
∙ Digits:
0,1,2,3,4,5,6,7,8,9
∙ Special Character
+ *& ^ % $ # @ ! ~ ` -- = > < .\ , : ;

25. What are logical operators?

A logical operator is used to compare or evaluate logical and relational expressions.


There three logical in C language. They are

Operator Meaning

&& AND

|| OR

! NOT

26. Write a note on scanf() function.

The scanf() function can be used to enter any combination of data, like single character,
string, integer and float values. The general format of the scanf() function is

scanf(“format specifier “, arg1, arg2……………..argn);

where format specifier string contains certain required formatting information, and avg1,
avg2….avgn are arguments that represent the individual input data item.

27. What are function?

A function is a set of statement to perform a specific task.

28. Define actual parameters.

Actual parameters are used for passing values or address from the calling function to a
function being called.

29. Write the general form of structure of C functions.

A C program basically has the following form


o pre-processor commands
o type definitions
o function prototype
o variable declaration
o function body

30. Give the syntax of if-else statement.

The if-else statement performs one of the two possible actions. The general format is

if(test expression)
{
true-statement block;
}
else
{
false-statement block;
}
next statement.

31. What is an identifier?

Identifier are names that are given to various program elements such as variables, functions
and arrays. Identifier consist of letters and digits, in any order, except that the first character
must be a letter. Both upper and lower case letters are permitted though common usage
favours the use of lower letters. The underscore is treated as a letter.

32. What is an escape sequence?

Some combination of characters have the special functions such as \n, \t and \b. They are
called as escape sequence.

33. What is the purpose of getchar() function?

It returns a character just entered from the standard input unit that is keyboard. The entered
character can be either assigned to a character variable or enclosed to the computer screen.

34. What is a character constant?

A character constant is a single character, enclosed within the pair of single quotation mark.
Example : ‘x’ , ‘5’

35. What is purpose of comma operator?

A set of expression separated by commas is a valid construct in the C language. For


example
int i,j;
The comma operator also used to link the related expression together. A comma
linked list of expression are evaluated left to right and the value of right-most expression is
the value of the combined expressions.
36. What is use of gets( ) function?

The gets( ) function is used to accept a string.

37. How to declare pointer variable?

A pointer declaration consists of a base type, an *, and the variable name. The general
form for declaring a pointer variable is

data_type *var_name;
For example
int *p;

38. List the four types of qualifiers.

∙ short
∙ long
∙ signed
∙ unsigned

39. What is an operator?

In C operator can be classified into various categories based on their utility and
action, a list operator types are given below
∙ Arithmetic operators
∙ Relational operators
∙ Logical operators
∙ Assignment operators
∙ Increment operators
∙ Conditional operators
∙ Bitwise operators
∙ Comma operators
∙ Other operators

40. What are the advantages of functions?

❖ It reduces the complexity in a program by reducing the code.


❖ Functions are easily understandable and execution is faster.
❖ It also reduces the time to run a program.
❖ It’s easy to find-out the errors due to the blocks made as function definition outside the
main function.

41. Write the syntax of while statement in C.

The general format of the while statement is

while(test_condition)
{
Body of the loop;
}

42. What is symbolic constant (pre-processor constant)?

❖ Names given to value that cannot be changed.


❖ Implemented with the #define program directive
#define N 300
❖ Note that pre-processor statement begin with a # symbol, and semicolon before the
program is actually compiled.
❖ In general, pre-processor constant are written in ‘UPPER CASE’.

43. What is a looping?

A looping is a process to do a job repeatedly with possible different data at each time.
The statement executed each time constitute the loop body, and each pass is called iteration.
A condition must be present to terminate the loop.

44. What is string constant?

A string constant is a sequence of character enclosed in double quotes. The characters


may be letters, numbers, special characters and blank space.
Eg: “Hello” ”1987” “WELL DONE” “?.....!” “5+3” “X”

45. What is the purpose of putchar( ) function?

The putchar( ) function display one character on the display monitor. The character to
be displayed is of type char. The syntax for putchar( ) function is as given below
putchar(variable);

46. Write a note on do-while statement.


In the do statement, the program proceeds to executes the body of the loop first. At
the end of the loop the test condition is evaluated. If the condition is true, the program
continues to execute the body of the loop. This process continues as long as the condition is
true.

47. Define scope of variables.

Scope refers to the visibility of variables of it is declared outside of any function


declaration, it is a global variable. If it is declared inside of any function declaration, it is a
local variable.

48. Write the syntax for switch () statement.


switch(expression)
{
case value-1:
Block-1;
Block-2;
………….
………….
default:
default block;
break;
}
statement-x;

49. What are register variable?

❖ Variables are used as a local variable.


❖ May be stored in register if possible.
❖ Default initial value is garbage value.

50. Mention the two categories of function

∙ Library function
∙ User – Defined function

1. 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
2. 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.

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

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

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

6. What are the logical operators available in ‘C’?


The logical operators available in ‘C’ are
&& - Logical AND
|| - Logical OR
! - Logical NOT
7. 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.

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

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

10. What is conversion specification?


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

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


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

12. 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 then it stops (iii) If the condition is false the control is
the execution the statements. transferred to the next statement of the loop.

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

14. What is a Modulo Operator?


‘%’ is modulo operator. It gives the remainder of an integer division
Example:
a=17, b=6. Then c=%b gives 5.

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

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

17. 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*/

18. What is a String?


String is an array of characters.

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

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

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

22. What will happen when you access the array more than its
dimension?
When you access the array more than its dimensions some garbage value
is
stored in the array.

23. Write the limitations of getchar( ) and sacnf( ) 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.

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

25. What is a Structure?


Structure is a group name in which dissimilar data’s are grouped together.

26. What is meant by Control String in Input/Output Statements?


Control Statements contains the format code characters, specifies the type
of data that the user accessed within the Input/Output statements.

27. What is Union?


Union is a group name used to define dissimilar data types. The union
occupies only the maximum byte of the data type. If you declare integer
and character, then the union occupies only 2 bytes, whereas structure
occupies only 3 bytes.

28. What is the output of the programs given below?


main() main()
{{
float a; float a;
int x=6, y=4; int x=6, y=4;
a=x\y; a=(float) x\y;
printf(“Value of a=%f”, a); printf(“Value of a=%f”,a);
}}
Output: Output:
1. 1.500000
29. Declare the Structure with an example?
struct name
{
char name[10];
int age;
float salary;
} e1, e2;

30. Declare the Union with an example?


union name
{
char name[10];
int age;
float salary;
} e1, e2;

31. What is the output of the following program when, the name given
with spaces?
main()
{
char name[50]; printf(“\n name\n”); scanf(“%s, name); printf(“%s”,name);
}
Output:
Lachi (It only accepts the data upto the spaces)

32. What is the difference between while(a) and while(!a)?


while(a) means while(a!=0)
while(!a) means while(a==0)

33. Why we don’t use the symbol ‘&’ symbol, while reading a String
through scanf()?
The ‘&’ is not used in scanf() while reading string, because the character
variable
itself specifies as a base address.
Example: name, &name[0] both the declarations are same.
34. What is the difference between static and auto storage classes?
Static Auto
Memory Memory
Zero Garbage value
Storage Local to the block in which the Local to the block in which the
Initial value variables is defined is defined.
Scope Value of the variable persists The block in which the
Life between different function calls. variable is defined.

35. What is the output of the program?


main() increment()
{ {
increment(); static int i=1;
increment(); printf(“%d\n”,i)
increment(); i=i+1;
} }
OUTPUT:
12 3

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

37. List out some of the rules used for ‘C’ programming.
· All statements should be written in lower case letters. Upper case letters
are only for
symbolic constants.
· Blank spaces may be inserted between the words. This improves the
readability of statements.
· It is a free-form language; we can write statements anywhere between ‘{‘
and ‘}’. a = b + c;
d = b*c;
(or)
a = b+c; d = b*c;
· Opening and closing braces should be balanced.

38. Define delimiters in ‘C’.


Delimiters Use
: Useful for label
; Terminates Statement
()[] Colon Used in expression and functions
{} Semicolon Parenthesis Square Used for array declaration Scope of
# Bracket Curly Brace Hash statement Preprocessor directive Vari
, Comma Separator

39. What do you mean by variables in ‘C’?


· A variable is a data name used for storing a data value.
· Can be assigned different values at different times during program
execution.

40. List the difference between float and double datatype.


S No Float Double Float / Double
Occupies 8 bytes in memory
Range : 1.7 e-308 to 1.7e+308
Format Specifier: % lf
Example : double y;
1 Occupies 4 bytes in memory There exists long double having a ra
2 Range : 3.4 e-38 to 3.8e+38 3.4 e -4932 to 3.4 e +4932 and occu
3 Format Specifier: % f bytes in memory.
4 Example : float a; Example: long double k;

41. Differentiate break and continue statement


S No break continue
1 Exits from current block / loop Loop takes next iteration
2 Control passes to next statement Control passes to beginning of loop
3 Terminates the program Never terminates the program
42. List the types of operators.
S No Operators Types Symbolic Representation
1 Arithmetic operators = , - , * , / and %
2 Relational operators > , < , == , >=, <= and !=
3 Logical operators && , || and !
4 Increment and Decrement ++ and –
5 operators =,+=,-=,*=,/=,^=,;=,&=
6 Assignment operators Bitwise & , | , ^ , >> , << , and ~
7 operators Comma operator ,
8 Conditional operator ?:

43. Distinguish between while..do and do..while statement in C. (JAN


2009)
While..DO DO..while
(i) Executes the statements within the (i) Executes the statements within the
while block if only the condition is true. while block at least once.
(ii) The condition is checked at the (ii) The condition is checked at the end of
starting of the loop the loop

44. Compare switch( ) and nestedif statement.


S No switch( ) case nested if
Test for equality ie., only constant It can equate relational (or)
values are applicable. logical expressions.
No two case statements in same Same conditions may be repea
switch. a number of times.
1 Character constants are automatically Character constants are autom
2 converted to integers. converted to integers.
3 In switch( ) case statement nested if In nested if statement switch c
4 can be used. be used.

45. Distinguish Increment and Decrement operators.


S No Increment ++ Decrement --
1 Adds one to its operand Subtracts one from its operand
2 Equivalent x = x + 1 Equivalent x = x - 1
3 Either follow or precede operand Either follow or precede operand
4 Example : ++x; x++; Example : --x; x--;

46. Give the syntax for the ‘for’ loop statement


for (Initialize counter; Test condition; Increment / Decrement)
{
statements;
}
· Initialization counter sets the loop to an initial value. This statement is
executed only once.
· The test condition is a relational expression that determines the number of
iterations desired or it determines when to exit from the loop. The ‘for’ loop
continues to execute as long as conditional test is satisfied. When condition
becomes false, the control of program exists the body of the ‘for’ loop and
executes next statement after the body of the loop.

47. What is the use of sizeof( ) operator?


· The sizeof ( ) operator gives the bytes occupied by a variable.
· No of bytes occupied varies from variable to variable depending upon its
data types.
Example:
int x,y;
printf(“%d”,sizeof(x));
Output:
2

48. What is a loop control statement?


Many tasks done with the help of a computer are repetitive in nature. Such
tasks
can be done with loop control statements.

49. What are global variable in ‘C’?


· This section declares some variables that are used in more than one
function. such
variable are called as global variables.
· It should be declared outside all functions.
50. Write a program to swap the values of two variables (without
temporary variable).
#include <stdio.h>
#include <conio.h>
void main( )
{
int a =5; b = 10;
clrscr( );
prinf(“Before swapping a = %d b = %d “, a , b);
a = a + b; B = a – b;
a = a – b;
prinf(“After swapping a = %d b = %d”, a,b);
getch( );
}
Output:
Before swapping a = 5 b = 10
After swapping a = 10 b = 5

51. Write short notes about main ( ) function in ’C’ program. (MAY
2009)
· Every C program must have main ( ) function.
· All functions in C, has to end with ‘( )’ parenthesis.
· It is a starting point of all ‘C’ programs.
· The program execution starts from the opening brace ‘{‘ and ends with
closing brace
‘}’, within which executable part of the program exists.

You might also like