Vous êtes sur la page 1sur 49

#define max value 10 void main() { int a=60; if(a/max value==6) printf("equal");

else printf("not equal"); } What will be output if you compile and execute the
above code? (a)equal (b)not equal (c)Run time error (d)Compiler error (2) #define
num int long void main() { num a=0;

printf("%d,%d,%d",a++,sizeof a++,sizeof(a++));

} What will be output if you compile and execute the above code? (a)3 2 4 (b)0 0 4
(c)0 4 4 (d)Compiler error (3)
#define short int long void main() {

printf("%d",sizeof(short));

} What will be output if you compile and execute the above code? (a)2 (b)4 (c)8
(d)Compiler error (4) #define float char void main() { float f=255;

printf("%d",sizeof(f++));

} What will be output if you compile and execute the above code? (a)1 (b)2 (c)8
(d)Compiler error (5) void main() { char f=255.0;

printf("%d",sizeof(f++));
} What will be output if you compile and execute the above code? (a)1 (b)8 (c)10
(d)Compiler error (6) void main() { f++; char f=255;

printf("%d",sizeof(f));

} What will be output if you compile and execute the above code? (a)1 (b)2 (c)4
(d)Compiler error (7) #define value 10\2 void main() {

printf("%d",value);

} What will be output if you compile and execute the above code? (a)5
(b)20 (c)102 (d)Compiler error (8) #define xxx 11\ 3 void main() {

printf("%ld",xxx);

} What will be output if you compile and execute the above code? (a)11 (b)3 (c)113
(d)Compiler error (9) #define option1 a++; printf("%d",a); #define option2
print("%d",a); void main() { int a=10;

if(a++) option1 else option2;

}
What will be output if you compile and execute the above code? (a)10 (b)11 (c)12
(d)Compiler error (10) //test.c void main() {

printf("%s",__FILE__);

} What will be output if you compile and execute the above code? (a)null (b)test.c
(c)url of current working directory (d)Compiler error (11) #include"stdio.h" void
main() {

#ifdef __stdio_h prinrf("defined"); #else printf("not defined"); #endif

}
What will be output if you compile and execute the above code? (a)defined (b)not
defined (c)Run time error (d)Compiler error (12) #include"stdio.h" void main()
{ const int a=1;

#if 5+~5+1 printf("%d",a+1); #elif 7 printf("%d",a+2); #else printf("%d",a+3);


#endif

} What will be output if you compile and execute the above code? (a)2 (b)3 (c)4
(d)Compiler error (13) #define conio.h #include "stdio.h" #define max 0\5 void
main()
{

#ifndef __conio_h #define conio.h printf("%s",__TIME__); #else #undef __conio_h


printf("%s",__DATE__); #endif

} What will be output if you compile and execute the above code? (a)Output will be
date of compilation (b)Output will be time of compilation (c)Output will be both
time of compilation and date of compilation (d)Compiler error (14) #define max 5
#define a max*max #define value a\a void main() { const int aa=5;

printf("%d",value+aa);

} What will be output if you compile and execute the above code? (a)5
(b)6 (c)10 (d)Compiler error (15) #define function(a,b) a##b void main() {

printf("%d",function(5,2));

} What will be output if you compile and execute the above code? (a)10 (b)2 (c)52
(d)Compiler error (16) #define find(a,b,c) #a#b#c void main() { int a=10; int b=20;
int c=30;

printf("%s",find(a,b,c)+1);

} What will be output if you compile and execute the above code? (a)102030 (b)02030
(c)bc (d)Compiler error (17) #define swap(x,y) x^=y^=x^=y void main() { int
a=10,b=20; swap(a,b);

printf("%d %d" ,a,b);

} What will be output if you compile and execute the above code? (a)10 20 (b)20 10
(c)0 10 (d)Compiler error (18) #define int long #define cal(x,y,z) x*y*z void
main() { int a=2; int b=cal(a++,a++,a++);

printf("%d,%d" ,a,b);

} What will be output if you compile and execute the above code? (a)5,0
(b)5,125 (c)5,60 (d)Compiler error (19) #define final(a,b,c) ++a+ ++b+ ++c void
main() {

printf("%d" ,final(1,2,3));

} What will be output if you compile and execute the above code? (a)6 (b)9 (c)10
(d)Compiler error (20) void one(); void two(); #pragma startup one 2 #pragma
startup two 1 void main() { printf("main ");

} void one() { printf("one "); }


void two() { printf("two "); } What will be output if you compile and execute the
above code? (a)main one two (b)one main two (c)main (d)two main one

Answer of preprocessor questions: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.


15. 16. 17. 18. 19. (d) (b) (b) (a) (a) (a) (c) (c) (d) (b) (b) (b) (b) (c) (c) (c)
(b) (a) (d)
20. (1) #define division 10\3 void main() { printf("%d",division); }

(d)

What will be output if you compile and execute the above code? (a)3 (b)4 (c)103
(d)Compiler error

(2) void display(); void calculate(); #pragma startup calculate #pragma exit
display void main() { printf("\ncquestionbank"); } void calculate()
{ printf("\njava-questionsbank"); } void display() { printf("\njavadoubt"); }
What will be output if you compile and execute the above code? (a)cquetionbank
Java-questionsbank javadoubt (b)java-questionban Cquetionbank javadoubt (c)
cquetionbank (d)Compiler error (3)

#include"stdio.h" #define sizeof(int) 4 void main() { int *p=NULL; printf("%d"


,p+1); } What will be output if you compile and execute the above code? (a)2 (b)4
(c)Garbage value (d)Null pointer error (4)

#define int double #define const struct #define char sizeof const student{ int s;
}; void main() { const student s; printf("%d" ,char(s)); } What will be output if
you compile and execute the above code? (a)1 (b)8 (c)Run time error (d)Compiler
error

(5)

#define cube(x) (x*x*x) void main() { int x=2,y,z; y=cube(++x); z=++y+386/cube(+


+x); printf("%d %d %d",++x,y,z); } What will be output if you compile and execute
the above code? (a)9 126 126 (b)4 27 126 (c)4 27 92 (d)Compiler error

(6)
#define find(a,b) a##b void main() { int a=10; int b=20; int ab=15;
printf("%d",find(a,b)-ab); } What will be output if you compile and execute the
above code? (a)0 (b)5 (c)1005 (d)Compiler error

(7) #define max 0\5 void main() { #if max printf("cquestionbnk"); #elif max+1
printf("java-questionsbank"); #else printf("blogspot.com"); #endif

} What will be output if you compile and execute the above code? (a)cquestionbank
(b)java-questionsbank (c)blogspot.com (d)Compiler error (8) #define option1 a++;\
printf("%d",a); #define option2 printf("%d",a); void main() { int a=10; if(a++)
{option1} else option2

} What will be output if you compile and execute the above code? (a)10 (b)11 (c)12
(d)Compiler error

Answer of preprocessor questions: 1. (c) 2. (b) 3. (a) 4. (b) 5. (a) 6. (a) 7. (a)
8. (c) What will be output of following program ?void main() { int a=320; char
*ptr; ptr=(char *)&a; clrscr(); printf("%d ",*ptr); getch(); } Output:64
Explanation: As we know int is two byte data byte while char is one byte data byte.
Char pointer can keep the address one byte at time. Binary value of 320 is 00000001
01000000 In 16 bit Memory representation of int a=320 is:

So ptr is pointing only first 8 bit which color is green and Decimal value is 64.
Memory representation of data type in detail. (q) What will be output of following
program? #include"stdio.h" #include"conio.h" void main() { void (*p)(); int (*q)();
int (*r)(); p=clrscr;
q=getch; r=puts; (*p)(); (*r)("cquestionblogspot.com"); (*q)(); } Output:
cquestionblogspot.com Explanation: p is pointer to function whose parameter is void
and return type is also void. R and q is pointer to function whose parameter is
void and return type is int . so then can hold the address of such function. How
can we read complex pointer in easy way click here. (q) What will be output of
following program? void main() { int i=3; int *j; int **k; j=&i; k=&j; printf( %u
%u %d } Answer: Output: 8085 6024 3 Explanation: Memory representation :
,k,*k,**k);

Here 6024, 8085, 9091 is any arbitrary address, it may be different.Value of k i s


content of k in memory which is 8085
Value of *k means content of memory location which address k keeps. k keeps addr
ess 8085 . content of at memory location 8085 is 6024 in Same way **k will 3. Short
cut way to calculate: Rule : * and & alaway cancel to each other i.e *&a=a So
*k=*(&j) since k=&j *&j=j =6024 And **k=**(&j)=*(*&j)=*j=*(&i)=*&i=i=3 To know
concept of pointer click me (q) What will be output of following program? void
main() { char far *p=(char far *)0x55550005; char far *q=(char far *)0x53332225;
clrscr(); *p=80; (*p)++; printf("%d",*q); getch(); } Output: 81 Explanation: Far
address of p and q are representing same physical address . Physical address of
0x55550005=( 0x5555)*(0x10)+(0x0005)= 0x55555 Physical address of
0x53332225=(0x5333*0x10)+(0x2225)=0x55555 *p =80, means content at memory location
0x55555 is assigning value 25 (*p)++ means increase the content by one at memory
location 0x5555 so now conten t at memory location 0x55555 is 81
*q also means content at memory location 0x55555 which is 26 What is far pointer ?
(q) What will be output of following program? #include"stdio.h" #include"string.h"
void main() { char *ptr1=NULL; char *ptr2=0; strcpy(ptr1," c");
strcpy(ptr2,"questions"); clrscr(); printf("\n%s %s",ptr1,ptr2); getch(); }
Output :( null) (null) Explanation: we cannot assign any string constant in null
pointer By strcpy function. Concept of string click me (q) What will be output of
following program? void main() { int huge *a=(int huge *)0x59990005; int huge
*b=(int huge *)0x59980015; if(a==b) printf("power of pointer"); else printf("power
of c"); getch();
} Output: power of pointer Explanation: Here we are performing relational operation
between two huge addresses. So first both a and b will normalize. a= (0x5999)*
(0x10) + (0x0005)=0x9990+0x0005=0x9995 b= (0x5998)* (0x10) +
(0x0015)=0x9980+0x0015=0x9995 Here both huge addresses are representing same
physical address. So a==b is true . What is huge pointer in detail? (q) What will
be output of following program? #include"stdio.h" #include"string.h" void main()
{ register a=25; int far *p; p=&a; clrscr(); printf("%d ",*p); getch(); } output
:error Explanation: register data type stores in CPU. So it has not any memory
address. Hence we cannot write &a. Storage class in c click me (q) What will be
output of following program? #include"stdio.h" #include"string.h" void main()
{ char far *p,*q; clrscr(); printf("%d %d",sizeof(p),sizeof(q)); getch(); } Output:
4 2 Explanation: p is far pointer which size is 4 byte. By default q is near
pointer which size is 2 byte. Theory of near pointer. (q) What will be output of
following program? void main() { int a=10; void *p=&a; int *ptr=p; clrscr();
printf("%u",*ptr); getch(); } Output: 10 Explanation: void pointer can hold address
of any data type without type casting. Any pointer can hold void pointer without
type casting. What is generic pointer? (q) What will be output of following
program? #include"stdio.h" #include"string.h" void main() {
int register a; clrscr(); scanf("%d",&a); printf("%d",a); getch(); } //if a=25
Output: error Explanation: register data type stores in CPU. So it has not any
memory address. Hence we cannot write &a. (q) What will be output of following
program? void main() { char arr[10]; arr="world"; clrscr(); printf("%s",arr);
getch(); } Output: compiler error Lvalue required Explanation: Actual declaration
of any array is: Char const arr[10]; So array name is constant pointer and we
cannot assign any value in constant data type after declaration. Concept of array
(q) Without using sizof operator find out size of following data type. (1)char
(2)int (3)float (4)double Answer: #include"stdio.h" #include"string.h" void main()
{ int a,b,c,d; char *p=0; int *q=0; float *r=0; double *s=0; a=(int)(p+1); b=(int)
(q+1); c=(int)(r+1); d=(int)(s+1); clrscr(); printf("%d %d %d %d",a,b,c,d);
getch(); } Output: 1 2 4 8 Explanation: address=next address Since initial address
of all data type is zero. So its next address will be size of data type. (q) What
will be output of following program? #include"stdio.h" #include"string.h" void
main()
{ int a=5,b=10,c; int *p=&a,*q=&b; c=p-q; clrscr(); printf("%d",c); getch(); }
output :1 Explanation: Difference of two same type of pointer will always one. (q)
What will be output of following program? unsigned long int (* avg())[3] { static
unsigned long int arr[3]={1,2,3}; return &arr; } void main() { unsigned long int
(*ptr)[3]; ptr=avg(); clrscr(); printf("%d",*(*ptr+2)); getch(); } Output: 3 What
is command prompt? Ans: Command prompt is text mode interface by which user can
enter the command f rom keyboard. It is non-graphical interface. These commands
invoke the specific program . What is command line argument? Ans: With help of main
function in c we can invoke the program. main function is called by operating
system. In main function has the parameter. They are: 1. Argument counter
2. Argument vector 3. Environment vector It is written as : main (int
argument_counter,char *argument_vector[ ],char *environment_vector[ ]) Argument
counter: It is integer type data type. It always count the number of ar gument
written to execute the any command and store that number. Example: void main (int
argument_counter ) { printf( Total number of argument :\t%d ,argument_counter); }
Save this program .Let file name is count.c and compile and execute the program
then open run in window then write cmd and press enter. Now go to your current
workin g directory (generally it is c:\tc\bin) Now if you will count command and
argument like India,pak etc then out put will be total number of argument including
count. Argument vector: It is array which contain address of char data type i.e
address of all argument. Example: void main(int argument_counter,char
*argument_vector[]) { int i; for(i=0;i{ printf("%s\n",argument_vector[i]); } } Save
this program as arg_vect.c. now write the command in command prompt. It is
displaying all the argument including arg_vect. How to create dos command in c?
Write a c program to create open command which is similar to type command in dos
operating system? Ans: #include void main(int count,char * argv[]) { int i; FILE
*ptr; char *str; char ch; if(count==1) { printf("The syntax of the command is
incorrect.\n"); } for(i=1;i{ ptr=fopen(argv[i],"r"); if(ptr==NULL) { printf("The
system cannot find the file specified."); if(count>2) printf("\nError occurred
while procesing : %s.\n",argv[i]); } else { if(count>2) {
printf("%s\n\n",argv[i]); } while((ch=getc(ptr))!=-1) printf("%c",ch); }
fclose(ptr); } } Save the above file as open.c ,compile and execute the go to
command mode (curre nt working directory) and write: open India.c To run the open
command in all directories and drive you will have to give the p ath of current
working directory in command mode. write: C:tc\bin>PATH c:\tc\bin Now press enter
key. Now your open command will work in all directory and drive. Write a c program
to create list command which is similar to dir command in dos operating system?
Ans: #include #include void main(int count,char *argv[]) { struct find_t q ; int a;
if(count==1) argv[1]="*.*"; a = _dos_findfirst(argv[1],1,&q); if(a==0) { while (!a)
{ printf(" %s\n", q.name); a = _dos_findnext(&q); } } else { printf("File not
found"); } } Save the above file as list.c ,compile and execute the go to command
mode (curre nt working directory) and write: list *.c To run the list command in
all directories and drive you will have to give the p ath of current working
directory in command mode. write: C:tc\bin>PATH c:\tc\bin Now press enter key. Now
your list command will work in all directory and drive. In same way you can create
cls ,copy con etc commands. Environment vector: It is array which contain address
of char data type i.e addr ess of all environment vector. Example: void main(int
argument_counter,char *argument_vector[],char *enviroment_vector[ ]) { int i=0;
while(enviroment_vector[i]) { printf("%s\n",enviroment_vector[i]); i++; }
} Its output will be list of all environment vectors. 1. Point out error, if any,
in the following program main() { int i=1; switch(i) { case 1:
printf("\nRadioactive cats have 18 half-lives"); break; case 1*2+4:
printf("\nBottle for rent -inquire within"); break; } } Ans. No error. Constant
expression like 1*2+4 are acceptable in cases of a switc h. 2. Point out the error,
if any, in the following program main() { int a=10,b; a>= 5 ? b=100 : b=200;
printf("\n%d",b); } Ans. lvalue required in function main(). The second assignment
should be written in parenthesis as follows: a>= 5 ? b=100 : (b=200); 9. We should
not read after a write to a file without an intervening call to ffl ush(), fseek()
or rewind() < TRUE/FALSE> Ans. True 13. In the following code, is p2 an integer or
an integer pointer? typedef int* ptr ptr p1,p2; Ans. Integer pointer 14. Point out
the error in the following program main() { const int x; x=128; printf("%d",x); }
Ans. x should have been initialized where it is declared. 16. What is the
difference between the following declarations? const char *s; char const *s; Ans.
No difference 17. What is the difference between the following declarations? const
char *const s; char const *const s; Ans. No difference 22. Point out the error in
the following program main() { int a=10; void f(); a=f();
printf("\n%d",a); } void f() { printf("\nHi"); } Ans. The program is trying to
collect the value of a "void" function into an int eger variable. 23. In the
following program how would you print 50 using p? main() { int a[]={10, 20, 30, 40,
50}; char *p; p= (char*) a; } Ans. printf("\n%d",*((int*)p+4)); 27. Point out the
error in the following program main() { const char *fun(); *fun()='A'; } const char
*fun() { return "Hello"; } Ans. fun() returns to a "const char" pointer which
cannot be modified 25. For the following C program int x(char *a) {a=(char *)
malloc(10*sizeof(char)); *a="hello"; } main() {char *a="new"; x(a); printf("%s",a);
} The output is a) Hello b) New c) Hello new d) Run time error Ans. (b) 9. int f()
void main() { f(1); f(1,2); f(1,2,3); } f(int i,int j,int k) { printf("%d %d
%d",i,j,k); } What are the number of syntax errors in the above?
Ans: None. 10. void main() { int i=7; printf("%d",i++*i++); } Ans: 56 11. #define
one 0 #ifdef one printf("one is defined "); #ifndef one printf("one is not defined
"); Ans: "one is defined" 12. void main() { intcount=10,*temp,sum=0; temp=&count;
*temp=20; temp=? *temp=count; printf("%d %d %d ",count,*temp,sum); } Ans: 20 20 20
13. There was question in c working only on unix machine with pattern matching. 14.
what is alloca() Ans : It allocates and frees memory after use/after getting out of
scope 15. main() { static i=3; printf("%d",i--); return i>0 ? main():0; } Ans: 321
16. char *foo() { char result[100]); strcpy(result,"anything is good");
return(result); } void main()
{ char *j; j=foo() printf("%s",j); } Ans: anything is good. 17. void main() { char
*s[]={ "dharma","hewlett-packard","siemens","ibm"}; char **p; p=s; printf("%s",+
+*p); printf("%s",*p++); printf("%s",++*p); } Ans: "harma" (p->add(dharma) && (*p)-
>harma) "harma" (after printing, p->add(hewlett-packard) &&(*p)->harma) "ewlett-
packard" 1. void main() { int d=5; printf("%f",d); } Ans: Undefined 2. void main()
{ int i; for(i=1;i<4,i++) switch(i) case 1: printf("%d",i);break; { case
2:printf("%d",i);break; case 3:printf("%d",i);break; } switch(i) case
4:printf("%d",i); } Ans: 1,2,3,4 3. void main() { char *s="\12345s\n";
printf("%d",sizeof(s)); } Ans: 6 4. void main() { unsigned i=1; /* unsigned char k=
-1 => k=255; */ signed j=-1; /* char k= -1 => k=65535 */ /* unsigned or signed int
k= -1 =>k=65535 */ if(iprintf("less"); else
if(i>j) printf("greater"); else if(i==j) printf("equal"); } Ans: less 5. void
main() { float j; j=1000*1000; printf("%f",j); } 1. 1000000 2. Overflow 3. Error 4.
None Ans: 4 6. How do you declare an array of N pointers to functions returning
pointers to functions returning pointers to characters? Ans: The first part of this
question can be answered in at least three ways: Q7. #define MAN(x,y) (x)>(y)?(x):
(y) { inti=10;j=5;k=0; k= MAX(i++,++j) printf(%d %d %d %d,i,j,k) } Ans. 10 5 0 Q3.
struct list{ int x; struct list *next; }*head; the struct head.x =100 Is the above
assignment to pointer is correct or wrong ? Ans. Wrong Q4.What is the output of the
following ? int i; i=1; i=i+2*i++; printf(%d,i); Ans. 4 Q5. FILE *fp1,*fp2;
fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1)
fclose(fp2)} a.error b. c. d. Ans. no error. But It will over writes on same file.
7. For the following C program
#define AREA(x)(3.14*x*x) main() {floatr1=6.25,r2=2.5,a; a=AREA(r1); printf("\n
Area of the circle is %f", a); a=AREA(r2); printf("\n Area of the circle is %f",
a); } What is the output? Ans. Area of the circle is 122.656250 Area of the circle
is 19.625000 15. main() { static i=3; printf("%d",i--); return i>0 ? main():0; }
Ans: 321 9. int f() void main() { f(1); f(1,2); f(1,2,3); } f(int i,int j,int k)
{ printf("%d %d %d",i,j,k); } What are the number of syntax errors in the above?
Ans: None. 10. void main() { int i=7; printf("%d",i++*i++); } Ans: 56 11. #define
one 0 #ifdef one printf("one is defined "); #ifndef one printf("one is not defined
"); Ans: "one is defined" 12. void main() { intcount=10,*temp,sum=0;
temp=&count; *temp=20; temp=? *temp=count; printf("%d %d %d ",count,*temp,sum); }
Ans: 20 20 20 53. For the following C program void main() { unsigned char c;
for(c=0;c!=256;c=c+2) printf("%d",c); getch(); } (a) 127 (b) 128 (c) 256 (d)
infinitely Ans: (d) 57. For the following program int i; i=2; i++; if(i==4)
{printf(i=4); } else {printf(i=3); } Output of the program ? a) b) c) d) 4 3
unpredictable none

Ans. (b) 58. What is FAT?. a) b) c) d) File Allocation Table File Access Table FDD
Allocation Table None of the above

(1)List the five c compiler? Ans: Name Work on O.S Name of microprocessor
1. Turbo c M.S DOS 8086 2. Ansic c LINUX/UNIX 80386 3. Borland c WINDOW 80386 4.
Microsoft c M.S DOS 8086 5. Visual c++ WINDOW 80386 Note:- 8086 is 16 bit
microprocessor while 80386 is 32 bit microprocessor. (2) Describe turbo c compiler?
Ans: Turbo c compiler is one of the most popular c compiler.It is based on DOS
operat ing system.It uses 8086 microprocessor which is 16 bit microprocessor. It
has 20 address buses and 16 data bus. It s word length is two byte. (3) What is
hexadecimal number system ? Ans: In hexadecimal number system we use 16 differen
digit so it s base is 16 TABLE Hexadecimal digit decimal equivalent binary
equivalent 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111
8 8 1000 9 9 1001 A 10 1010 B 11 1011 C 12 1100 D 13 1101 E 14 1110 F 15 1111 To
convert the binary number into hexadecimal number: Make the group of four binary
digit from right to left put the equivalent hexade cimal digit using TABLE. e.g
binary number =11000111110101 group of four digit from right 11 0001 1111 0101 to
make group of four digit of left most digit 11,add two zero to the leftt side i.e
0011 now put the eqivalent hexadecimal digit form table 0011 0001 1111 0101 3 1 F 5
So,equivalent hexadecimal number will be 31F5 (4) What will address range which can
repersent in 20 bit ? Ans: in binary in hexadecimal Minimum possible number 0000
0000 0000 0000 0000 0000 Maximum possible number 1111 1111 1111 1111 1111 FFFF In c
any hexadecimal number statr with 0x 0r 0X So,address range will be 0x0000 to
0xFFFF It is 1MB memory range. Note. 2^10 = 1KB 2^20 = 1MB 2^30 = 1GB
Where 10,20,30 are number of bit. (5)What is difference betweent TSR and TSO
program? Ans :TSO means terminate but stay outside.It is those program, which
release the main memory after the executon of the program.e.g Vcd cutter, turbo c
compiler. TSR means terminate but stay residence .It is those program, which after
the exe cution of the program does not release the RAM (main memory).e.g antivirus.
(1) Why there are so many c compilers? Ans: (3)How many keywords are in c? Ans: 43
(6)What is difference between .com program and .exe program? Ans: Both .com and
.exe program are executable program but .com program execute faste r than .exe
program.All driver are .com program. (2) How many type of error in c. Ans: 183
Memory orgnization To be a good programmer is very necessay to understand the
memory structure. (1) What is memory cell? Ans:

Entire RAM has divided in number of equal part, which is known as memory cell.Ca
pcity of each cell is to store one-byte data. i.e char a resevre one memory cell
while float a reseve four memory cell. Each memory cell has unique addresss.Address
are always in whole number an incre sing order. (6) What is residence memory? Ans:

RAM has divided into two parts: (1) Extended memory (useless) (2) Residence
memory : When any program is excuted it is stored in the residence memory .For
turbo c, i t has 1MB residence memory i.e when we open turbo c it store 1MB in the
RAM. (3) What is physical address ? Ans: 20 bit address of the memory cell is known
as physical address or real address.I n 20 bit we can repersent address from
0x00000 to 0xFFFFF.

(4) What is segmentation? Ans:


Residential memory of RAM of size 1MB has divided into 16 equal part.These part is
called segment.Each segment has size is 64KB. 1MB=16*64KB This process of division
is known as segmentation. (5) What is necesity of segmentation? Ans: Physical
address are 20 bit.But we have no pointer of 20 bit.So pointer can not access whole
residential address .So to solve this problem we have three differe nt pointer and
segmentation has done. (6) What is offset address? Ans: Each segment has divided
into two parts. 1. Segment no (4bit) 2. Offset address (16 bit) Each segment has
same offset address but different segment number. Suppose physical address is
0x500F1 Then it s segment number is 5 and offset address is 00F1. (7) Write a
program to find the offset address of any variable? Ans: Void main () { int x;
scanf( %d ,&x); printf( %p ,x); } Note. %p is used to find the offset address (in
hexadecimal) of any variable. (8) What is data segment? Ans: Segment number 8 has
special name which is known as data segment. It has divided into four parts.

1. Stack area:All automatic variables are created into stack area.Default storage
class of any local variable is auto.This variable may be int, char, float, array,
pointer, s truct, union etc.It also return fuction argument and return address.It
follow LI FO datastructure. It has two part one for initialize variable another for
non-in itialize variable.All initialize variable are more nearer than unintialize
varia ble and vice versa. 2. Data area : All static and extern variable are created
in the data area. 3. Heap area: Malloc and calloc always allocate memory in the
heap area.It is used for dynamic memory allocation.It s size depends upon free
space in the memory. 4. Code area: Fuction pointer can only access code area.Size
of this area is always fixed and it is read only area.

(10) What will output: void main() { int a=5,b=6,c=7; printf( %d,%d,%d );
} Ans: Output: 7 6 5 Explanation: Default sotrage class int a=5 is auto.Since it
automatic variable it will create in the stack area. It will store in the stack as
Stack always follows LIFO datastructure. In the printf statement name of variable
is not written explicitly.So default ou tput will content of Stack which will be in
the LIFO order i.e 7 6 5. (9) what will be output: void main() { int a=5 ,b,c=7;
printf( %d %d %d ); } Ans: Output: 7 5 garbage value Explanation: Automatic
variable a and c has initialized while b has not initilize.Initialize variable are
more nearer than non initialize variable .They will be stored in th e stack.So due
to LIFO first output will be 7 then 6 (since a is more nearer tha n b with respect
to c) then any garbage value will be output which is persent in the stack. (7) How
many number system in c. Ans: There are three type of number system in c: 1.
Decimal number e.g 25 2. Octal number e.g 025 3. Hexadecimal number e.g 0x25 (8)
010110 is which type of number in c? Ans: Octal integer constant (Since it starts
with zero) Note. C has not binary integer constant. (1) Without using any semicolon
(;) in program write a c programm which output i s: HELLO WORLD ? Ans: void main()
{ if(printf("HELLO WORLD")) { } } (1)What will be output ? void main() { char a[5];
a[0]='q'; a[1]='u'; a[2]='e'; clrscr(); printf("%s",a); getch();
} Output: garbage Explanation: %s is used for string but a is not a string it is
only array of cha racter since its last character is not null character. If you
will write a[3]= \0 ; then output will be que. (2) Write a scanf statement which
can store one line of string which includes wh ite space. Ans: void main() { char
a[30]; clrscr(); scanf("%[^\n]",a); printf("%s",a); getch(); } (3) Write a c
program in which a scanf function can store a paragraph at time ? Ans: void main()
{ char a[30]; clrscr(); scanf("%[^\t]",a); printf("%s",a); getch(); } Note:
Paragraph will end when you will press tab key. (4)In the following program void
main() { char a[30]; } How much aryy a is reserving memory space ? Ans: It is not
reserving any memory space because array a has only declared it has no t
initialized .Any not initialized variable doesn t reserve any memory space.

what will be output of the following program? void main(){ float a=0.7; if(a<0.7)
{ printf("C"); } else{ printf("C++"); } }
For solution and detail explanation click here (2) what will be output of the
following program? void main() { int i=5,j; j=++i+++i+++i; printf("%d %d",i,j); }
For solution and detail explanation click here (3) what will be output of the
following program? void main() { int i=1; i=2+2*i++; printf("%d",i); } For solution
and detail explanation click here (4) what will be output of the following program?
void main() { int a=2,b=7,c=10; c=a==b; printf("%d",c); }
For solution and detail explanation click here (5) what will be output of the
following program? void main() { int x; x=10,20,30; printf("%d",x); } For solution
and detail explanation click here (6) what will be output of the following program?
void main() { int a=0,b=10; if(a=0) { printf("true"); } else { printf("false"); } }
For solution and detail explanation click here (7) what will be output of the
following program? void main() {
int a; a=015 + 0x71 +5; printf("%d",a); } For solution and detail explanation click
here (8) what will be output of the following program? void main() { printf("%d %d
%d",sizeof(3.14),sizeof(3.14f),sizeof(3.14L)); } For solution and detail
explanation click here (9) what will be output of the following program? void
main() { int x=100,y=20,z=5; printf("%d %d %d"); } For solution and detail
explanation click here (10) what will be output of the following program? void
main(){ int a=2; a=a++ + ~++a; printf("%d",a); } For solution and detail
explanation click here
(11) what will be output of the following program? void main() { int a; a=sizeof(!
5.6); printf( %d ,a); } For solution and detail explanation click here (12) what
will be output of the following program? void main() { float a; (int)a= 45; printf(
%d ,a); } For solution and detail explanation click here (13) what will be output
of the following program? void main() { int i=5; int a=++i + ++i + ++i;
printf( %d ,a); } (1)What will be output void main() { clrscr();
printf("%d",sizeof(3.8)); getch();
} output: 8 Explanation: 3.8f is float constant, 3.8 is double constant and 3.8L is
long dou ble constant .Here are finding size of double constantan which is 8. For
more detail click here (2) What will be output ? void main() { char *str1="powla";
char *str2="er"; clrscr(); printf("%s\b\b%s",str1,str2); getch(); } output: power
Explanation: \b escape sequence back the cursor one position left .We are using two
/b so after writing str1 cursor is at the position of l of powal .So when it write
er it will override the la so output will be power. (3)What will be output ? void
main() { int a=270; char *p; p=(char *)&a; clrscr(); printf("%d",*p); getch(); }
output: 16 (4)What is missing statement of in the following program ? void main() {
int sort(int,int); int I; i=sort(5,6); } int sort(int a,int b) { int c; c=a; a=b;
b=c; return a; } Ans: Function sort returning a value but we are not using return
value so there is weastge of two byte memory. So missing statement is ,there should
statement w hich uses the return value. (5)Write following in term of if and else :
void main() { int a=1,b=2,c=3; clrscr(); if(a==5&&b==6&&c==7) printf("india"); else
printf("pak"); getch(); } Ans: void main()
{ int a=1,b=2,c=3; clrscr(); if(a==1) { if(b==2) { if(c==3) { printf("india"); }
else { printf("pak"); }} else { printf("pak"); } } else { printf("pak"); } getch();
} (6)Give the memory representation of struct xxx { char a; int b; char c; }; Ans:
Memory representation :

More detail click here (7) Write the following program in term of switch and case ?
void main() { int a=3; if(x>2) { printf( INDIA IS BEST ); } else{ printf( PAK IS
BEST ); } } Ans: if condition always return two value. 1 if condition is true. 0 if
condition is false. So program is void main() { int x=3; switch(x>2) { case
0:printf("India is best");
break; case 1:printf("Pak is best"); } getch(); } (8) What will be output ? void
main() { int far *a=(int far*)0x50000011; int far *b=(int far*)0x50010001; int huge
*c=(int huge*)0x50000011; int huge *d=(int huge*)0x50010001; clrscr(); if(a==b)
printf("I know C"); else printf("I don't know C"); if(c==d) printf("\nI know C");
else printf("\nI don't know C"); getch(); } Output: I don t know C I known C
Explanation: far pointer always compare its whole far address.Since both or not
equal so first output is :I don t know C Huge pointer always compare its physical
address both c and d are representing s ame physical address so a and b are equal.
More detail click here (9) What will be output ? #define power(a) #a void main()
{ clrscr(); printf("%d",*power(432)); getch(); } Output : 52 Explanation: # is
string zinging operator. It make the string constant of any data. So 432 is
converted into 432 by macro power .Now * 432 means first char which is 4.Since we
ar e using %d so it will print ASCII value of char 4 i.e 52 More detail click here
(10) What will be output ? void main() { int arr[]={1,2,3,4,5,6}; void xxx(int[5]);
xxx(arr); getch(); } void xxx(int ch[5]) { clrscr(); printf("%d",-1[ch]); }
Output : -2
Explanation: We are passing the array by xxx function. 1[ch] means *(ch+1) which is
ch[1] =2. (11) What is difference between a,b,c and in following declaration ?
#define xxx char * typedef char * yyy; void main() { yyy a,b; xxx c,d; } Ans: Both
and b are char * type but c is char * type while d is char type. (12) Write a c
program to find the HCF of any two number ? Ans: void main() { int a,b,c; scanf( %d
%d%d ,a,b,c); clrscr(); while((c=a%b)!=0) { a=b; b=c; } printf("%d",b); getch(); }
(13) What will be output ? void main() { int a=5; { a++; } clrscr();
printf("%d",a); getch(); } Ans :6 (14) What will be output ? void main() { int a=5;
{ int a=7; a++; printf( %d ,a); } clrscr(); printf("%d",a); getch(); } Output: 8 5
Explanation: Scope of the auto variable is within {} if it is declared in {}.Als o
local variable has more priority than global variable. How to calculate RoM and RaM
sizes reading from map file... RO stands for Read Only. It is the const variable
that does not change througho ut the program.
RW stands for Read/Write. It is the variable contains initial value, but it may
change when the program runs. ZI stands for Zero Initialize data. It is the
variable (i.e. buffer) that uses to hold data when the program runs. RAM usage is
the combination of RW and ZI. ROM usage is the conbination of Code, RO, and RW. RW
is part of the ROM usage b ecause it needs to hold initial data. That's this
reason, we can save RAM usage by changing RW into RO data, if we can identify it
does not change throughout t he program.

Vous aimerez peut-être aussi