Exercise

1. What is the output of this program?

#include<stdio.h>
struct test {
int x = 0;
char y = 'A';
};
int main()
{
struct test t;
printf("%d, %c", s.x, s.y);
return 0;
}

A. 0 A
B. Error
C. garbage value garbage value
D. None of these

View Answer


2. What is the output of this program?

#include <stdio.h>
struct test {
int x;
char y;
} test;
int main()
{
test.x = 10;
test.y = 'A';
printf("%d %c", test.x,test.y);
return 0;
}


A. 10 A
B. garbage value garbage value
C. Compilation Error
D. None of these

View Answer


3. What is the output of this program?

#include <stdio.h>
struct result{
char sub[20];
int marks;
};
void main()
{
struct result res[] = { {"Maths",100},
{"Science",90},
{"English",85}
};
printf("%s ", res[1].sub);
printf("%d\n", (*(res+2)).marks);
}

A. Maths 100
B. Science 85
C. Science 90
D. Science 100

View Answer


4. What will be the size of the following structure?

struct demo{
int a; char b; float c; }

A. 12
B. 8
C. 10
D. 9

View Answer


5. What is the output of this program?

#include<stdio.h>
void main()
{
struct demo{
char * a;
int n;
};
struct demo p = {"hello", 2015};
struct demo q = p;
printf("%d", printf("%s",q.a));
}

A. hello
B. 5hello
C. hello5
D. 6hello

View Answer


6. What is the output of this program?
#include<stdio.h>
int main()
{
union demo {
int x; int y;
};
union demo a = 100;
printf("%d %d",a.x,a.y);
}

A. 100 0
B. 100 100
C. 0 0
D. Compilation Error

View Answer


7.

#include<stdio.h>
int main()
{
enum days {MON=-1, TUE, WED=4, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d", MON, TUE, WED, THU, FRI, SAT);
return 0;
}

A. -1 0 4 5 6 7
B. -1 0 1 2 3 4
C. 0 1 2 3 4 5
D. Error

View Answer


8.What is the purpose of "rb" in fopen() function used below in the code?

FILE *fp;
fp = fopen("demo.txt", "rb");

A. Open "demo.txt" in binary mode for reading
B. Create a new file "demo.txt" for reading and writing
C. Open "demo.txt" in binary mode for reading and writing
D. None of the above

View Answer


9. Which files will get closed through the fclose() in the following program?

void main()
{
FILE *fp, *ft; fp = fopen("a.txt", "r"); ft = fopen("b.txt", "r"); fclose(fp,ft); }

A. a, b
B. a
C. b
D. Error in fclose

View Answer


10. When fopen() is not able to open a file, it returns

A. EOF
B. NULL
C. Run-time Error
D. None of the above

View Answer


11. getc() returns EOF when

A. When getc() fail to read the character
B. When end of file is reached
C. Both A and B
D. None of the above

View Answer


12. What is the output of this program?

#include<stdio.h>
int main(){
FILE *fp;
char *str;
fp=fopen("demo.txt","r");//demo.txt :you are a good programmer
while(fgets(str,6,fp)!=NULL)
puts(str);
fclose(fp);
return 0;
}

A. you are a good programmer
B. e a good programmer
C. you ar
D. you are

View Answer


13. What is the output of this program?

#include<stdio.h>
int main(){
char c;
FILE *fp;
fp=fopen("demo.txt","r");
while((c=fgetc(fp))!=EOF)
printf("%c",c);
fclose(fp);
return 0;
}

A. It will print the content of file demo.txt
B. It will print the content of file till it encouter new line character
C. Compilation Error
D. None of the above

View Answer


14. What is the output of this program?

#include<stdio.h>
int main(){
char c;
FILE *fp;
fp=fopen("demo.txt","a+");
// demo.txt : hello you are reading a file
fprintf(fp," demo");
fclose(fp);
fp=fopen("myfile.txt","r");
while((c=fgetc(fp))!=EOF)
printf("%c",c);
fclose(fp);
return 0;
}

A. hello you are reading a file
B. hello you are reading a file demo
C. demo
D. None of the above

View Answer


15. What is the output of this program?

#include<stdio.h>
int main(){
struct simp
{
int i = 6;
char city[] = "chennai";
};
struct simp s1;
printf("%d",s1.city);
printf("%d", s1.i);
return 0;
}

A. chennai 6
B. Nothing will be displayed
C. Runtime Error
D. Compilation Error

View Answer


16. What is the output of this program?

#include<stdio.h>
struct
{
int i;
float ft;
}decl;
int main(){
decl.i = 4;
decl.ft = 7.96623;
printf("%d %.2f", decl.i, decl.ft);
return 0;
}

A. 4 7.97
B. 4 7.96623
C. Compilation error
D. None of the above

View Answer


17. What is the output of this program?

#include<stdio.h>
int main(){
struct bitfields
{
int bits_1: 2;
int bits_2: 4;
int bits_3: 4;
int bits_4: 3;
}bit = {2, 3, 8, 7};
printf("%d %d %d %d", bit.bits_1, bits.bit_2, bit.bits_3, bits.bit_4);
}

A. Runtime error
B. Compilation error
C. 2 3 8 7
D. -2 3 -8 -1

View Answer


18. What is the output of this program?

void main()
{
struct bitfields {
int bits_1: 2;
int bits_2: 9;
int bits_3: 6;
int bits_4: 1;
}bit;
printf("%d", sizeof(bit));
}

A. 2
B. 3
C. 4
D. 0

View Answer


19. What is the output of this program?

#include<stdio.h>
int main(){
struct leader
{
char *lead;
int born;
};
struct leader l1 = {"AbdulKalam", 1931};
struct leader l2 = l1;
printf("%s %d", l2.lead, l1.born);
}

A. Compilation error
B. Garbage value 1931
C. AbdulKalam 1931
D. None of the above

View Answer


20. What is the output of this program?
#include<stdio.h>
struct employee
{
char *empname;
int salary;
};
int main()
{
struct employee e, e1;
e.empname = "Sridhar";
e1 = e;
printf("%s %s", e.empname, e1.empname);
return 0;
}

A. Garbage value Sridhar
B. Sridhar Garbage value
C. Sridhar Sridhar
D. Compilation Error

View Answer



Discussion

* You must be logged in to add comment.