Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By Ravi Kiran

CBSE CLASS XII

2003 Annual Paper

Q.1.a. What is the difference between global variables and local variables? Give an example to illustrate the same.

Ans:

The local variables are the variables defined within any function (or block) and are hence accessible only within the block in which they are declared. In contrast to local variables, variables declared outside of all the functions in a program are called global variables. These variables are defined outside of any function, so they are accessible to all functions. These functions perform various operations on the data. They are also known as External Variables.
Eg: #include<iostream.h>
int a,b;
void main()
{ float f;
---;
---;
}
In the above program segment, a and b are global variables, we can access a and b from any function. f is local variable to function main( ), we can access f from main( ) only.

Q.1.b. Name the header file, to which the following built-in function belongs. (i) strcmp( ) (ii)getc( ) .

Ans:

(i) strcmp( ) - string.h
(ii)getc( ) - stdio.h

Q.1.c. Rewrite the following program after removing all the syntax error(s) if any.
#include<iostream.h>
void main( )
{ int P[ ]={90,10,24,15};Q,Number=4;
Q=9;
for[int I=Number-1;I>=0,I--]
switch(I)
{ case 0;
case 3:cout>>P[I]*Q<<endl;break;
case 1:
case 2: cout<<P[I]+Q;
}
}

Ans:

#include<iostream.h>
void main( )
{ int P[ ]={90,10,24,15},Q,Number=4;
Q=9;
for(int I=Number-1;I>=0;I--)
switch(I)
{ case 0:
case 3:cout<<P[I]*Q<<endl; break;
case 1:
case 2: cout<<P[I]+Q;
}
}

Paper By Mr. Ravi Kiran
Email Id : [email protected]