Академический Документы
Профессиональный Документы
Культура Документы
1. The value of automatic variable that is declared but not initialized will be?
[A] 0
[B] 1
[C] Unpredictable
[D] None of above
2. Choose the correct statement
[A] An identifier may start with an underscore [B] An identifier may end
with an underscore
[C] IF is a valid identifier
[D] All of above
3. The const feature can be applied to?
[A] An identifier
[B] An array
above
[D] Martin
[D] Rang
[D]
[C] External,
11. How would you round off a value from 1.66 to 2.0?
[A] ceil(1.66)
[B] floor(1.66)
[C] roundup(1.66)[D]
roundto(1.66)
12. By default a real number is treated as a
[A] float
[B] double
[C] long double
13. Which of the following is not user defined data type? 1 :struct book
{ char name[10]; float price; int pages; }; 2 :
long int l = 2.35; 3 :
enum day {Sun, Mon, Tue, Wed};
[A] 1
[B] 2
[C] 3
[D] Both 1 and 2
14. Is the following statement a declaration or definition? extern int i;
[A] Declaration [B] Definition
[C] Function
[D] Error
15. Identify which of the following are declarations 1 :
extern int x; 2
:float square ( float x ) { ... } 3 : double pow(double, double);
[A] 1
[B] 2
[C] 1 and 3
[D] 3
16. In the following program where is the variable a getting defined and
where it is getting declared? #include int main() { extern int a;
printf("%d\n", a); return 0; } int a=20;
[A] extern int a is declaration, int a = 20 is the definition
[B] int a = 20 is declaration, extern int a is the definition
[C] int a = 20 is definition, a is not defined
[D] a is declared, a is not defined
17. When we mention the prototype of a function?
[A] Defining
[B] Declaring
[C] Prototyping
[D] Calling
20. Global variable are available to all functions. Does there exist a
mechanism by way of which it available to some and not to others.
[A] Yes
[B] No
b=10;
a=a^b;
b=a^b;
a=b^a;
printf("\na= %d b= %d",a,b);
If any pointer is pointing the memory address of any variable but after some
variable has deleted from that memory location while pointer is still pointing
such memory location. Such pointer is known as dangling pointer and this
problem is known as dangling pointer problem.
Later:
}
Output: Garbage value
Explanation: variable x is local variable. Its scope and lifetime is within
the function call hence after returning address of x variable x became
dead and pointer is still pointing ptr is still pointing to that location.
Solution of this problem: Make the variable x is as static variable. In
other word we can say a pointer whose pointing object has been deleted
is called dangling pointer.
6. What will be output of following c program?
void main(){
int *ptr;
printf("%u\n",ptr);
printf("%d",*ptr);
}
Output: Any address
Garbage value
Here ptr is wild pointer because it has not been initialized. There is
difference between the NULL pointer and wild pointer. Null pointer points
the base address of segment while wild pointer doesnt point any specific
memory location.
7. What is and why array in c ?
An array is derived data type in c programming language which can store
similar type of data in continuous memory location. Data may be primitive
type (int, char, float, double), address of union, structure, pointer,
function or another array.
Example of array declaration:
int arr[5];
char arr[5];
float arr[5];
long double arr[5];
char * arr[5];
int (arr[])();
double ** arr[5];
Array is useful when:
(a) We have to store large number of data of similar type. If we have large
number of similar
kind of variable then it is very difficult to remember name of all variables
and write the program.
For example:
//PROCESS ONE
void main(){
int ax=1;
int b=2;
int cg=5;
int dff=7;
int am=8;
int raja=0;
int rani=11;
int xxx=5;
int yyy=90;
int p;
int q;
int r;
int avg;
avg=(ax+b+cg+dff+am+raja+rani+xxx+yyy+p+q+r)/12;
printf("%d",avg);
}
If we will use array then above program can be written as:
//PROCESS TWO
void main(){
int arr[]={1,2,5,7,8,0,11,5,50};
int i,avg;
for(int i=0;i<12;i++){
avg=avg+arr[i];
}
printf("%d",avg/12);
}
Advantage of using array:
1. An array provides singe name .So it easy to remember the name of all
element of an array.
2. Array name gives base address of an array. So with the help increment
operator we can visit one by one all the element of an array.
3. Array has many application data structure.
Array of pointers in c:
Array whose content is address of another variable is known as array
pointers. For example:
void main(){
float a=0.0f,b=1.0f,c=2.0f;
float * arr[]={&a,&b,&c};
b=a+c;
printf("%f",arr[1]);
}
}
Output: 5 10
(b)Pass by reference: In this approach we pass memory address actual
variables in function as a parameter. Hence any modification on parameters
inside the function will reflect in the actual variable.
For example:
#include<stdio.h>
void main(){
int a=5,b=10;
swap(&a,&b);
printf("%d %d",a,b);
}
void swap(int *a,int *b){
int *temp;
*temp =*a;
*a=*b;
*b=*temp;
}
Output: 10 5
11. Do you know nested loop. Explain by an example ? Answer
A loop inside another loop is known as nested loop. We can write any loop
inside any loop in c
i.e. we can write for loop inside the loop or while loop or do while loop etc.
For example:
(a)
void main(){
int i,j,k;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf(" %d",i+j);
}
}
getch();
}
(b)
void main(){
int i,j,k;
do
while(0)
for(;0;)
printf("cbyexample");
while(0);
getch();