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



Discussion

* You must be logged in to add comment.