0% found this document useful (0 votes)
173 views

File Handling and Bitwise Operators

The document discusses file handling and bitwise operators in C programming. It includes 16 questions about concepts like bitwise NOT, bitwise AND, bitwise OR, file positioning using fseek, reading from files using fgets and fgetc. The questions cover topics like manipulating bits using operators, positioning within files, reading contents from files and understanding return values from functions like fseek.

Uploaded by

pratik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views

File Handling and Bitwise Operators

The document discusses file handling and bitwise operators in C programming. It includes 16 questions about concepts like bitwise NOT, bitwise AND, bitwise OR, file positioning using fseek, reading from files using fgets and fgetc. The questions cover topics like manipulating bits using operators, positioning within files, reading contents from files and understanding return values from functions like fseek.

Uploaded by

pratik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

File Handling And bitwise Operators

1.
#include<stdio.h>
int main(void)
{
unsigned short int a = 10;

a = ~a;
printf("%u\n", a);

return 0;
}

A. -11
B. 65525
C. 65526
D. -9

Answer: B

2.
#include<stdio.h>
int main(void)
{
int a = 144;

if (a = a >> 4)
printf("a=%d\n", a=a<<3);

return 0;
}

A. 72
B. 144
C. 288
D. 36

Answer: A

Augest 2019 – December 2019 1


File Handling And bitwise Operators
3.

#include<stdio.h>
int main(void)
{
if (!(7 | 8))
printf("Honesty");
if ((~7 | 0x000f) != 8)
printf("is the best policy\n");
return 0;
}

A. Honesty is the best policy


B. Honesty
C. is the best policy
D. run time error

Answer: C

4.
#include <stdio.h>
#define MOBILE 0x01
#define LAPPY 0x02
int main(void)
{
unsigned char item=0x00;
item |=MOBILE;
item |=LAPPY;
printf("I have purchased ...:");

if(item & MOBILE)


{
printf("Mobile, ");
}
if(item & LAPPY)
{
printf("Lappy");
}
return 0;
}

Augest 2019 – December 2019 2


File Handling And bitwise Operators
A. I have purchased ...:
B. I have purchased ...:Mobile, Lappy
C. I have purchased ...:Mobile,
D. I have purchased ...:Lappy

Answer: B

5.

#include <stdio.h>
int main(void)
{
char var=0x04;
var = var | 0x04;
printf("%d,",var);
var |= 0x01;
printf("%d",var);
return 0;
}

A. 8,9
B. 4,5
C. 8,8
D. 4,4

Answer: B

6.
#include <stdio.h>
int main(void)
{
int x=10; x &= ~2;printf("x = %d",x);
return 0;
}
A. x = 10
B. x = 8
C. x = 12
D. x = 0

Answer: B

Augest 2019 – December 2019 3


File Handling And bitwise Operators
7.
#include <stdio.h>
int main(void)
{
char flag=0x0f;
flag &= ~0x02; printf("flag = %d",flag);
return 0;
}

A. flag = 13
B. flag = d
C. flag = 22
D. flag = 10

Answer: A

8.
#include <stdio.h>
int main(void)
{
FILE *fp = stdout;
int num=102;
fprintf(fp, "%d-%c-%d-%c",num,num-32,num+=32,num-=32);
return 0;
}
A. 102-F-102-f
B. 102-f-70-F
C. 70-f-102-F
D. 70-F-70-f

Answer: A

9.
if fseek function fail to move to desised position in
file. It returns
A. 0
B. non zero error error numbers
C. nothing
D. run time error

Answer: B

Augest 2019 – December 2019 4


File Handling And bitwise Operators
10.
What should be the output of the following code?
if file contents following data in sunbeam.txt
[Sunbeam DMC DAC DBDA DESD]

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

fseek(fp, 0, SEEK_END);
fseek(fp, -15L, SEEK_CUR);
fgets(c, 7 , fp);

puts(c);
return 0;
}

A. prints "C DAC "


B. prints "DMC DA"
C. prints garbage value
D. prints "C DAC"

Answer: A

11.
fseek(filepointer, 0L, SEEK_SET);
can be represent in coding ?

A. fseek(filepointer, 0L, O);


B. rewind(filepointer);
C. fseek(fp, 0, SEEK_END-2); or
fseek(fp, 0, SEEK_CUR-1);
D. All of above

Answer: D

Augest 2019 – December 2019 5


File Handling And bitwise Operators
12.
if sunbeam.txt file contents [sunbeam] data in file what
will be output ?

#include <stdio.h>
int main(void)
{
FILE *fpRead=NULL;
char ch;

fpRead = fopen("sunbeam.txt", "a+");


while((ch=fgetc(fpRead))!= 1*-1)
printf("%c", ch);

return 0;
}

A. prints sunbeam
B. prints sunbeam infinitly
C. no output
D. run time error

Answer: A

13.

#include <stdio.h>
int main(void)
{
char *ptr = "SunBeam Pune and Karad";
printf(ptr+7-5+5);
return 0;
}

A. prints Pune and Karad


B. prints Sunbeam Pune and Karad
C. prints garbage values
D. none of above

Answer: A

Augest 2019 – December 2019 6


File Handling And bitwise Operators
14.
#include <stdio.h>
int main(void)
{
printf("\?\?!\n");
return 0;
}

A. Compile Time Error


B. Run Time Error
C. ??!
D. \?\?!\n

Answer: C

15.
#include <stdio.h>
int main(void)
{
char str[] = "\\t SunBeam \\0 \\n \0 Pune";
printf("%s", str);
return 0;
}

A. \t SunBeam \0 \n
B. \\t SunBeam \\0 \\n \0 Pune
C. \t SunBeam \0 \n \0 Pune
D. none of above

Answer: A

16.

#include <stdio.h>
int main(void)
{
printf("\n no of char = %d ",
printf("\n\n welcome to sunbeam \t\t pune "));
return 0;
}

Augest 2019 – December 2019 7


File Handling And bitwise Operators
A.

welcome to sunbeam pune


no of char = 30

B.
no of char = 30

welcome to sunbeam pune

C.

\n\n welcome to sunbeam \t\t pune


no of char = 34

D. none of above

Answer: A

Augest 2019 – December 2019 8

You might also like