Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
53 views

File Handling and Bitwise Operators: Fopen Fseek Fseek Fgets Puts

The document discusses file handling and bitwise operators in C programming. It provides examples of code snippets using functions like fopen, fgets, fseek for file handling and bitwise operators like &, |, ^, <<, >>. It also includes questions and answers related to these topics to test understanding.

Uploaded by

mayande rohini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

File Handling and Bitwise Operators: Fopen Fseek Fseek Fgets Puts

The document discusses file handling and bitwise operators in C programming. It provides examples of code snippets using functions like fopen, fgets, fseek for file handling and bitwise operators like &, |, ^, <<, >>. It also includes questions and answers related to these topics to test understanding.

Uploaded by

mayande rohini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

File Handling And bitwise Operators

1.
if file contents following data in sunbeam.txt
[PUNE KARAD SATARA MUMBAI]
#include <stdio.h>
int main( void )
{
FILE *fp=NULL; char c[1024];
fp = fopen("Sunbeam.txt", "r");
fseek(fp, 0, SEEK_END);
fseek(fp, -9L, SEEK_CUR);
fgets(c, 5, fp);
puts(c);
return 0;
}

A. RA MUM
B. ARA
C. TARA M
D. run time error

Answer: D

2.
if file contents following data in sunbeam.txt
[PUNE KARAD SATARA MUMBAI]
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fptr=fopen("sunbeam.txt","r"); char ch;
while(!feof(fptr))
{
printf("%c",fgetc(fptr));
fseek(fptr,-1,SEEK_CUR);
}
fclose(fptr);
return 0;
}

February 2020 – Augest 2020 1


File Handling And bitwise Operators
A. P
B. Infinite loop
C. No output
D. I

Answer: B

3.
By default stream stdout is

A. Unbuffered
B. Fully Buffered
C. Line Buffered
D. None of these

Answer: A

4.
A mode which is used to open an existing file for both
reading and writing

A. "w"
B. "w+"
C. "r+"
D. "wb+"

Answer: C

5.
Which of the following fuinction is most appropriate
for storing the data type of any data type?

A. puts()
B. fprintf()
C. fwrite()
D. All of the above

Answer: C

February 2020 – Augest 2020 2


File Handling And bitwise Operators
6.
#include <stdio.h>
int main(void)
{
int x=1;
printf("%d,%d",~x-x>>1,~x-x<<1);
return 0;
}

A.-3,-4
B.-1,-6
C.-2,-6
D.-2,-4

Answer :C
7.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int num1=2;
int result=num1<<3;
if(result & num1)
printf("True");
else
printf("false");
return 0;
}

A. True
B. false
C. ERROR
D. Abnormal terminate

Answer: B

February 2020 – Augest 2020 3


File Handling And bitwise Operators
8.
#include <stdio.h>
int main(void)
{
printf("%d %d %d %d",4<<2,4>>3,10>>3,10<<2);
return 0;
}

A. 16 0 1 40
B. 8 12 3 30
C. 16 1 1 10
D. 16 0 10 30

Answer: A

9.
#include <stdio.h>
int main(void)
{
int i=32,j=65,k;

k = j ^ 32;
printf(" k=%d",k);

k=j<<2;
printf(" k=%d",k);

k=i>>5;
printf(" k=%d",k);
return 0;
}

A. k=97 k=265 k=1


B. k=97 k=260 k=1
C. k=90 k=260 k=1
D. k=97 k=1 k=1

Answer: B

February 2020 – Augest 2020 4


File Handling And bitwise Operators
10.
#include <stdio.h>
int main(void)
{
int num = 5;
while (~num)
{
printf("Test");
}
return 0;
}
A. Test
B. Infinite loop
C. No output
D. Compile time error

Answer: B

11.
#include <stdio.h>
int main(void)
{
int num = 12;
int j=0;
while (num>>=j)
{
printf("%d,%d ",num,j);
j++;
}
return 0;
}

A. 12,0 6,1 1,2


B. 12,0 6,1 1,3
C. Infinite loop
D. 12,0 6,1 2,2

Answer: A

February 2020 – Augest 2020 5


File Handling And bitwise Operators
12.
#include <stdio.h>
int main(void)
{
int result = 0;
if (result&=~5)
printf("Test1");
else
printf("Test2");
return 0;
}

A. Test1
B. Test2
C. No output
D. Abnormal termination

Answer: B

13.
#include <stdio.h>
int main(void)
{
int a,b,c;
a=5;
b=10;
c=printf("%d\0",b) + b++;
printf(" %d",c);
return 0;
}

A.11 12
B.10 12
C.12 12
D.Compile time error

Answer: B

February 2020 – Augest 2020 6


File Handling And bitwise Operators
14.
#include <stdio.h>
int main(void)
{
int b=10;
int num1;
int result;
result = scanf("%d",num1) + ++b;
printf("%d",result);
return 0;
}

A.12
B.11
C.10
D.run time error

Answer: D

15.
#include <stdio.h>
int main(void)
{
printf("\\ \? Test \0 Hello \n");
return 0;
}

A.\\ \? Test Hello


B.\ ? Test
C.\\ ? Test Hello
D.\ ? Test Hello

Answer:-B

February 2020 – Augest 2020 7


File Handling And bitwise Operators
16.
What will be the o/p of the following code if run on
ternimal as ./a.out

#include <stdio.h>
int main(void)
{
printf("\nC programming Language\nDennis Ritchie\t\n");
printf("\n\tSunbeam\rpune\n");
return 0;
}

A.
C programming Language
Dennis Ritchie

Sunbeam pune

B.
C programming Language
Dennis Ritchie
Sunbeam pune

C.
C programming Language
Dennis Ritchie

pune Sunbeam

D.
C programming Language Dennis Ritchie

pune Sunbeam

Answer: C

February 2020 – Augest 2020 8

You might also like