0% found this document useful (0 votes)
5 views6 pages

File Handling and Bitwise Operators: Fseek Fseek Fseek Fseek

The document contains a series of programming questions and answers related to file handling and bitwise operators in C. It covers topics such as file reading methods, the use of fseek and rewind, and bitwise operations with examples. Each question is followed by multiple-choice answers, with the correct answer indicated.

Uploaded by

Akash Kamble
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)
5 views6 pages

File Handling and Bitwise Operators: Fseek Fseek Fseek Fseek

The document contains a series of programming questions and answers related to file handling and bitwise operators in C. It covers topics such as file reading methods, the use of fseek and rewind, and bitwise operations with examples. Each question is followed by multiple-choice answers, with the correct answer indicated.

Uploaded by

Akash Kamble
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

File Handling And bitwise Operators

1.
rewind(filepointer); can be represent in form of fseek?
A. fseek(filepointer, 0L, 0);
B. fseek(filepointer, 0L, SEEK_SET);
C. fseek(filepointer, 2L, SEEK_END);
D. fseek(filepointer, 1L, SEEK_SET);
E. both A and B
Answer: E

2.
#include<stdio.h>
int main()
{
FILE *fpRead=NULL;
char ch;
fpRead = fopen("myfile.c", "r");
while((ch=fgetc(fpRead))!=NULL)
printf("%c", ch);

return 0;
}

A. Print the contents of file "myfile.c"


B. Print the contents of file "myfile.c" upto NULL
character
C. Infinite loop
D. Error in program
Answer: C

3.
#include<stdio.h>
int main()
{
FILE *fpRead=NULL;
char ch;
fpRead = fopen("myfile.c", "a");
while((ch=fgetc(fpRead))!=EOF)
printf("%c", ch);

return 0;
}

1
File Handling And bitwise Operators

A. Read the contents of file "myfile.c"


B. Print the contents of file on console "myfile.c" upto
NULL character
C. Infinite loop
D. No output exit status 0
Answer: D

4.
What should be the output of the following code?
if file contents following data in [Link]
[Sunbeam DMC DAC DBDA DESD]

#include <stdio.h>
int main( void )
{
FILE *fp=NULL;
char c[1024];
fp = fopen("[Link]", "r");

fseek(fp, 0, SEEK_END);
fseek(fp, -11L, SEEK_CUR);
fgets(c, 5, fp);

puts(c);

return 0;
}

A. Sunb
B. C DB
C. C DA
D. c DBDA
Answer :B

5.
if we want to read three records of students from file in
student array arr.
which statement can be use from following ?
A. fread(arr, sizeof(struct student) ,3, filepointers );
B. fread(arr, sizeof(arr) ,1, filepointers );

2
File Handling And bitwise Operators

C. fread(arr, sizeof(struct student) ,1, filepointers );


D. A and B
Answer: D

6.
Which of the following functions are ideally suited for
reading the contents of a file record by record?
A. fgetc()
B. fgets()
C. fread()
D. gets()
Answer: C

7. Which of the following true about FILE *fp.


A. FILE is a keyword in C for representing files and fp is
a variable of FILE type.
B. FILE is a structure and fp is a pointer to the
structure of FILE type
C. FILE is a stream
D. FILE is a buffered stream

Answer: B

8.
fseek() should be preferred over rewind() mainly because
A. rewind() doesn’t work for empty files
B. rewind() may fail for large files
C. In rewind, there is no way to check if the operations
completed successfully
D. All of the above
Answer: C

9.
#include<stdio.h>
int main(void)
{
int i=4, j=8;
printf("%d, %d, %d", i|j&j|i, i|j&&j|i, i^j);
return 0;
}

3
File Handling And bitwise Operators
A. 4, 8, 0
B. 1, 2, 1
C. 12, 1, 12
D. 0, 0, 0
Answer: C

10.
#include<stdio.h>
int main()
{
printf("%c", ~('C'*-1));
return 0;
}

A. B
B. C
C. Compile Error
D. Runtime Error
Answer: A

11.
#include<stdio.h>
int main()
{
printf("%d %d ", 32<<1, 32<<0);
printf("%d %d ", 32<<-1, 32<<-0);
printf("%d %d ", 32>>1, 32>>0);
printf("%d %d ", 32>>-1, 32>>-0);

return 0;
}

A. Garbage values
B. 64 32 16 32 16 32 64 32
C. 32 64 32 16 32 16 32 64
D. 64 32 0 32 16 32 0 32

Answer: B

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

A. 4 >> 1 8 >> 1
B. 4 >> 18 >> 1
C. 2 >> 4 garbage value >> garbage value
D. 2 >> 4

Answer: C

13.
void myfunbyaddress(int *x, int *y)
{
*y ^= *x;
*x^= *y;
*y^= *x;
}
int main(void)
{
int no1 = 10, no2 = 20;
int *ptr1 = &no1, *ptr2 = &no2;

printf(" *ptr1=%d ptr2=%d ", *ptr1, *ptr2);

myfunbyaddress(ptr1, ptr2);

printf(" *ptr1=%d ptr2=%d ", *ptr1, *ptr2);

return 0;
}

A. *ptr1=10 ptr2=20 *ptr1=20 ptr2=10


B. *ptr1=10 ptr2=20 *ptr1=10 ptr2=20
C. *ptr1=10 ptr2=20 *ptr1=10 ptr2=10
D. *ptr1=10 ptr2=20 *ptr1=20 ptr2=20
Answer: A

5
File Handling And bitwise Operators
14.
#include <stdio.h>
int main( void )
{
int a = 4;
if (!(a >> 3))
{
printf("a = %d a>>3 =%d\n", a, a>>3);
}
return 0;
}

1. a = 4 a>>3 = 0
2. a = 0 a>>3 = 0
3. a = 4 a>>3 = 4
4. no output

Answer: A

15.
#include <stdio.h>
int main( void )
{
int c = 10 ^ 5;
int d = c & 2;
int f = d ^ c;

printf("%d\n", c);

return 0;
}

A. 10
B. 15
C. 5
D. 20
Answer: B

You might also like