Breaking News
You are here: Home / Paper Solutions / SEM-2 / C Programming / C Programming Paper solution OCTOBER/NOVEMBER 2008

C Programming Paper solution OCTOBER/NOVEMBER 2008

C Programming Paper solution OCTOBER/NOVEMBER 2008

Q-1 Answer following briefly:

(i) How can you declare a variable as constant?

Answer: To do this, one declares a constant as if it was a variable but add ‘const’ before it. One has to initialize it immediately in the constructor because, of course, one cannot set the value later as that would be altering it. For example,

Const int Constant1=96;


(ii) How do you mean by overflow and underflow of data?

Answer: stack overflow occurs when the on–chip stack capacity is exceeded. This can be detected by a comparison of the top-pointer, the last-pointer and the index specified for a create-frame operation ( for push). Initially the top-pointer is set to 1 and the last-pointer to 0, placing a dummy element on the stack.


If an index specified for a read access is greater than the number of valid on–chip stack elements, a stack underflow occurs


iii) How do variable and symbolic names differ?

Answer: An instance of an object is created when a variable is declared. Declaration of a symbolic name just defines a name that can be used in a program.



int muthu1208; // an instance of an object #define MUTHU 25 // definition of a symbolic name


(iv) What is trigraph character? How are they useful?

Answer: A trigraph is a set of three characters that represents one character in the C character set. The set of trigraph sequences was defined in the ANSI Standard to allow users to use the full range of C characters, even if their keyboards do not implement the full C character set. Trigraph sequences are also useful with input devices that reserve one or more members of the C character set for internal use; e.g., the Hazeltine family of terminals, which reserves the tilde `~’ as its escape character.


(v) What is the purpose of qualifier const and volatile?

Answer: When any variable has qualified with const keyword in declaration statement then it is not possible to assign any value or modify it by the program. But indirectly with the help of pointer its value can be changed.

When any variable is not qualified by const variable then its default qualifier is not const


.There is not any keyword for not const. Its meaning is that value of variable can be changed after the declaration statement by the program.





When any variable has qualified by volatile keyword in declaration statement then value of variable can be changed by any external device or hardware interrupt. If any variable has not qualified by volatile keyword in declaration statement, then compiler will take not volatile as default quantifier .There is not any special keyword for not volatile. Not volatile means when any variable has qualified by volatile keyword in declaration statement then value of variable cannot be changed by any external device or hardware interrupt.


(vi) Explain significance of main ( ).

Answer: Function main() is the application’s main routine where a program starts execution.It is the first user-written function run when a program starts.Object-oriented C++ programs consist mostly of classes, but there’s always at least one C-like function: main(). main() is called more or less at the beginning of the program’s execution, and when main() ends, the runtime system shuts down the program. main() always returns an int, as shown below:


int main() {

// …Your Code goes here…




main() has a special feature: There’s an implicit return 0; at the end. Thus if the flow of control simply falls off the end of main(), the value 0 is implicitly returned to the operating system. Most operating systems interpret a return value of 0 to mean “program completed successfully.”


main () is the only function that has an implicit return 0; at the end. All other routines that return an int must have an explicit return statement that returns the appropriate int value.


Note that this example shows main() without any parameters. However, main() can optionally declare parameters so that it can access the command line arguments, just as in C


(vii) Given statement int a-10,b=20,C; Determine

(i)  a+=10;


(ii)  b+3/2 a+=10 ;


Is an assignment statement, in which value of a will added with 10 and then the resulted value will be assigned to a value of a is 10,


a += 10 means a=a+10; thus a=20 b+3/2


Value of b i.e. 20 plus 3/2 i.e. 1.5, thus the total value will be 21.5


Q-2(a) Explain different type of type conversions.


 Type Conversion:


Type conversion means to convert a higher data type to lower data type. For the purpose of type conversion we required to use the type case operator, which lets you manually promote or demote a value. It is a unary operator which appears as the data type name followed by the operand inside a set of parentheses.


There are two type of type conversion:


  1. Implicit type conversion
  2. Explicit type conversion
  1. Implicit type conversion
    • C permits mixing of constant and variables of different type in an expression. C automatically converts any intermediate values to proper type so that the expression can be evaluated without losing any significance
    • This automatic conversion is known as implicit type conversion
    • Conversion Hierarchy
    • C Datatype Conversion Hierarchy
    • The final result of an expression is converted to type of the variable on the left of the assignment sign before assigning the value to it. However, the following changes are introduced during the final assignment.
      1. Float to int causes truncation of the fractional part.
      2. double to float causes rounding of digit.
      3. long int to int causes dropping of the excess higher order bits
  2. Explicit type conversion
  • In implicit type conversion, casting is based on automatically and lower to higher.
  • We have just discussed how C performs type conversion automatically. However, there are instances when we want to force a type conversion in a way that is different from the automatic conversion.
  • The process of such a local conversion is known as explicit conversion or casting a value.
  • Where type-name is one of the standard C data types. The expression may be constant, variable or an expression.
  • Some examples of casts and their actions are shown in:


  • x= (int) 7.5
  • a= (int) 21.3/ (int) 4.5
  • b= (double)sum/n
  • y= (int) (a+b)
  • z= (int)a+b


Q-2(b) what are different types of decision making statement in ‘C’?


  • p=cos ((double) x)

There are five types of decision making statement in ‘C’ languages.

  1. Simple if
  2. If…..else
  3. Nested if
  4. Ladder else…if
  5. Switch case 


Q-2 (c) Write a program to print the following Patten for n=5.


void main ()

int n,i,j,k,a; clrscr();

printf(“ENTER THE ANY VALUE IS n ”); scanf(“%d”,&n);

printf(“ ”);


printf(“\n”); a--;







c paper solutions


Q-2 (c) Write a program to find the value of sum for given series up to X. Sum=1+2/2! +3/3! +……………+X/X!


void main ()
int n,i,j;

float Sum=0,a=1,k,c; clrscr();

printf(“ ENTER THE ANY VALUE IS n ”); scanf(“%d”,&n);

printf(“\n %d * %d !”,i,i); for(j=1;j<=c;j++)

printf(“\n a------ 0.28”,a); k=j/a;

printf(“\n k----- 028”,k); sum=sum+k;


printf(“\n sum=%0.28”,sum); 
getch ();






 Sum=1+2/2! +3/3! +4/4! +5/5! Sum=?


Q-3 (a) how can you format an output of a ‘C’ program.




Like get char, there is an analogous function put char for writing characters one at a time to the terminal. It takes the form as shown below:


Put char (variable name);


Where variable name is a type char variable containing a character. This statement displays the character contained in the variable name at the terminal. For example, the statements.


Answer = ‘Y’; putchar (answer);


Will display the character Y on the screen. The statement putchar (‘\n’);

Would cause the cursor on the screen to move to the beginning of the next line.


For example :->


void main ()

char alphabet; printf(“enter an alphabet”); putchar (‘\n’); alphabet=getchar ();
if (is lower (alphabet))
Put char (topper (alphabet));

putchar (to lower (alphabet));


getch ();



We have seen the use of printf function for printing caption and numerical result. It is highly desirable that output are produced in such a way that they understandable and are an in an easy-to use form. It is therefore necessary for the programmer to give careful consideration to the appearance and clarity of the output produced by his program.


The printf statement provides certain features that can be effectively exploited to control the alignment and spacing of print-outs on the terminals.


The general form of printf statement is:

Printf(“control string”,arg1,arg2,…,argn);

  • Control string consists of three types of items:
  • Characters that will be printed on the screen as they appear.
  • Format specification that define the output format for display of each item.
  • Escape sequence characters such as \n, \t, and \b.
  • The control string indicates how many arguments follow and what there types are. The arguments arg1, arg2,…,argn are the variables whose value are formatted and printed according to the specifications of the control string. The arguments should match in number, order and type with the format specifications.


A simple format specification has the following form:

%w.p type-spcifire

Where w is an integer number that specific the total number of columns for the output values and p is onther integer number that specifies the number of digits to the right of the decimals point or the number of character to be printed from a string. Both w and p are optional. Some examples of format printf statements are:

printf(“programming in c”); 
printf(“ ”);
printf(“ \n”); 


printf never supplies a newline automatically and therefore multiply printf statements may be used to build one line of output. A newline can be introduced by the help of a new line character ‘\n’.


Q-3 (b) Explain for loop in detail with proper examples.


The for loop is another entry-controlled loop that provides a more concise loop control structure the general of the loop is. The general form of the loop is


The execution of the four statements is as follow:

  1. Initialization of the control variables is done first, using assignment  statement such as i=1 and count=0.The variable I and count are known as loop –control variable.
        • for (initialization; test-condition; increment)
          Body of the loop;
  2. The value of the control variable is tested using the test-condition is a relational expression, such as I <10 that determines when the loop will exit. If the condition is true, the body of the loop is executed; otherwise the loop is terminated and the execution continues with the statement that immediately follows the loop. 
  3. When the body of the loop is executed, the control is transferred block to the for statement after evaluating the last statement in the loop. Now, the control variable is increment using an assignment statement such as I =i+1 and the new value of the control variable is again tested to see whether it satisfies the loop condition. If the condition is satisfied, the body of the loop is again executed. This process

continues till the value of the control variable fails to satisfy the test-condition. Consider the following segment of a program:


This for loop is executed 10 times and prints the digit 0 to 9 in one line. The three section enclosed within parentheses must be separated by semicolon at the end of the increment section, x=x+1.

The for statements allows for negative increment. For example, the loop discussed above can be written as follow:

For (x=9 ; x<9 ; x--)

Will never be executed because the test condition fails at the very beginning itself.

Let us again consider the problem of sum of squares of integers discussed in section.

This problem can be coded using the for statement as follows:


The body of the loop

Sum=sum + n*n;

Is executed 10 times for n=1,2,3,…..,10 each time incrementing the sum by the square of the value of n.


Q-4 (a) Explain any 2 string functions with example.


strcpy ()


This library function is used to copy a string and can be used like this strcpy (destination, source).(It is not possible in C to do this : string1=string2 ).


Take a look at the following example:


str_two=”def”; strcpy(str_one,str_two);



This library function is used to compare two strings andcan be usd like this:strcmp(str1,str2).

If the first string is greater than the second string a number greater than null is returned.

If the first string is less than the second string a number less than null is returned.


If the first and the second string are equal a null is returned. The look at an example:

printf(“ENTER TH NAME :”);


 if (strcmp(name,”india”)==0)



Q-4 (b) Explain need of array variable .what is the difference between character array and numeric array.


An array lets you declare and work with a collocation of values of the same type. Let’s say you want to declare four intergers.with the knowledge from the last few tutorials you would do something like this:


int a ,b ,c, d;


What if you wanted to declared a thousand variables? That will take you a long time to type. This is where array are come in handy.


An easier way is to declare an array of integers.

int a [4];


The four separate integers inside this array are accessed by an index. Each element can be accessed by using square brackets with the element number inside. All arrays start at element zero and will go to n-1.(in this case from 0 to 3). So if we want to fill each element you get something like this :

int a [4];



if you want to use an element , for example for printing you can do this:



Q-4 (c) Write a program to do following on a given string.

INPUT: Patel Shiv Kumar





void main ()

char str[50]; int i;

puts (“ENTER A STRING”); gets (str);

for (i=0; i<=str[i]! =’\0’; i++)
if (str [i] ==’ ‘) printf(“\n”);

puts (“str[i]”);



Q-5 (a) what is advantages of structure over array?


With an array you can store only one type of component .However; we cannot use an array if we want to represent a collection of data items of different types using a single name.


While in a structure you can add as you prefer, and also include methods for them.


  • A structure is a convenient tool for handling.
  • A structure and an array are different things.
  • An array stores multiple copies of a defined item.
  • A structure contains a group of data types (ints, floats, chars, and even other structs).
  • You can define an array of structures.
  • If you want to store the details of 10 student names, markers of three subjects, total & percentage, one would declare the following array variables. 

Char stud Name [10][20];

 Int sci [10], math [10],

eng [10], total [10];

Float per [10];


To handle this many number of array variable will be difficult. Instead of it, we can wrap this entire variable into one package using structure in C.

After creating a structure of student it is treated as template and we can have number of variable of this given data type.


Q-5 (b) Explain use of bit field in union.


In C languages the user can decide the number of bits in memory (RAM) to be allocated to a variable. It overcomes the prescribed number of bytes allocated to a variable by the compliers.

In some of the cases, a variable can have either 0 or 1 like the variable flags. Strictly speaking .flag users only one bit to store either 0 or 1, but it is declared as int which occupies 16 bit in RAM. In order to overcome this 16 bit default allocation and to allot just one bit, the bit field may be defined as a structure of size 1 bit as shown below.

union one_bit
unsigned int x: 1;

} flag; 

union u1

int a; int b;


struct s1


union u1; int c;

} dave;



In both these examples, the members can be accessed as dave.a, dave.b, and dave.c. An anonymous union must be a number of, or nested within another anonymous union that is a member of, a named structure or union. If a union is declared at file scope without a following union only declares the union tag tom:

Union tom
Int b; Float c;


The variables b and c from this union cannot be used at file scope, and the following statement will generate errors:



Uses of bit fields:

The following are the uses of bit fields:


The storage space required to store the details in a structure is economically used by the bit fields.


The saving of storage space is considerably high when a large quantity of such data is stored.

Download Paper Solutions from Below Link

About admin

Scroll To Top