You are on page 1of 39

What will be the output of the following program?

#include<stdio.h>
int main()
{
enum checkpoint {point1, point2, point3} s1, s2;
s1 = point1;
s2 = s1 + 1;
printf("%d",s2);
return 0;
}

2
Compiler error
0
1
----------------------------------------Which one of the following is an illegal operation on a structure?
Copying & assignment
Using address operator
Direct comparison
None of these
-----------------------------------------Question Number 3
What is the correct value returned to the operating system upon the successful c
ompletion of a program?
1
0
-1
Programs do not return a value
--------------------------------------------What will be the output of the following program?

#include<stdio.h>
int main( )
{
union a
{
int i ;
char ch[2] ;
} ;
union a u ;
u.ch[0] = 3 ;
u.ch[1] = 2 ;
printf ( "%d %d %d", u.ch[0], u.ch[1], u.i ) ;
return 0;
}

3 2 515
515 2 3
3 2 5
None of these
--------------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int x;
x=10,20,30;
printf("%d",x);
return 0;
}

30
Compiler error
10
None of these
---------------------------------What will be the output of the following program?
#include <stdio.h>
int main()
{
int a;
printf("%d",a^a);

return 0;
}

1
0
Unexpected
Runtime error
---------------------------------------------What will be the output of the following program?
#include<stdio.h>
int main(){
int a=5,b=4;
while(a!=0)
{
if(a=((a^b)|a) == 0)
continue;
else break;
}
printf("%d", a);
return 0;
}

Infinite loop
The value 0 is printed continuously (infinite loop)
0
Runtime error
----------------------------------------------------Which one of the following statements is correct about the following function?
fun ( int a, int b )
{
int a ;
a = 20 ;
return a ;
}

Error: Missing parenthesis in return statement


Error : The function should be defined as int fun ( int a, int b )

Error : Redeclaration of a
None of these
-----------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
while(1)
{
int n;
char d;
n = scanf("%c",&d);
if(d=='z')
printf("%d",n);
break;
}
return 0;
}

Infinite loop
Runtime error
Compiler error
Compiles successfully, but no output
-----------------------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int a = 1, b = 2, c = 3;
printf("The value of a is %d", ++a);
func();
printf(" The value of a is %d", ++a);
return 0;
}
void func()
{
int a = 10;
return 0;
}

The value of a is 2 The value of a is 2


The value of a is 2 The value of a is 3

The value of a is 1 The value of a is 10


Compiler error
------------------------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int x=1;
int y=1;
int i;
for(i=2;i<=6;i++)
{
x=x+i;
y=y*(i+1)/(i-1);
printf("%d ",x);
printf("%d ",y);
}
return 0;
}

Prints random value


3 3 6 6 10 10 15 15 21 21
Runtime error
Compiler error
---------------------------What will be the output of the following program ?
#include<stdio.h>
int main()
{
if("lakshya"=="lakshya")
printf("Equal");
else
printf("Not equal");
return 0;
}

Not equal
Equal
Compiler error

None of these
------------------------------What will be the output of the following program?
#include<stdio.h>
int main();
const int k=100;
int main()
{
int a[100];
int sum=0;
for(k=0;k<100;k++)
*(a+k)=k;
sum+=a[--k];
printf("%d",sum);
return 0;
}

0 1 2 3
It prints the address of the array elements
It is not possible to create array of references
Compiler error
---------------------------------------------The function unlink(filename) is used to __________.
remove link between file and buffer
remove the existing file from the directory
remove the contents of file only
None of these
--------------------------------------------------------------What will be the output of the following program?
#include<stdio.h>
int print_arr(float **p)
{
printf(" 0 %f 1 %f 2 %f\n",p[0][0],p[0][1],p[0][2]);
}
int main()
{
float arr[2][3] = {{0,1,2},{3,4,5}};
float **fl_arr;
fl_arr = (float *)arr;
print_arr(fl_arr);
fl_arr++;

print_arr(fl_arr);
return 0;
}

Compiler error
Runtime error
Compiles successfully
No output
-----------------------------------------------------------Which is the correct method of opening a file for writing as binary file?
FILE *f = fwrite("test.bin", "b");
FILE *f = fwriteb("test.bin");
FILE *f = fopenb("test.bin", "w");
FILE *f = fopen("test.bin", "wb");
------------------------------------------------------What will be the output of the following program?
#include<stdio.h>
int main(int argc, char *argv[])
{
char arr1[] = "Welcome";
char arr2[] = "Welcome";
if (arr1==arr2)
printf ("Both arrays are same");
else
printf ("Both arrays are not same");
return 0;
}

Both arrays are same


Compiler error
Both arrays are not same
Runtime error
---------------------------------------------Which one of the following options is TRUE about the following programs A and B?

A.
char str[100];
strcpy(str,"Hello");
File *fp = fopen("Binary.txt", "wb");
fwrite(str,sizeof(char),strlen(str),fp);
fclose(fp);
B.
char str[100];
strcpy(str,"Hello");
File *fp = fopen("Ascii.txt", "w");
fwrite(str,sizeof(char),strlen(str),fp);
fclose(fp);

Both the programs throws compiler error


Compiles successfully and both the programs give different output
Compiles successfully and both the programs give the same output
None of these
--------------------------------------------------------What will be the output of the following program?
#include<stdio.h>
int main();
const int kvar=100;
int main()
{
int avar[100];
int sumvar=0;
for(kvar=0;kvar<100;kvar++)
*(avar+kvar)=kvar;
sumvar+=a[--kvar];
printf("%d",sumvar);
return 0;
}

Compiler error
It will print 1 to 100
It will throw runtime Exception
None of these
------------------------Question Number 2
In the following code, what is the correct way to increment the variable ptr ?

void main()
{
int *ptr;
struct test_struct
{
int a;
float b;
};
test_struct test_array[5];
ptr = test_array;
}

ptr = ptr + sizeof(test_struct)


ptr = ptr + sizeof(test_arrray)
ptr = ptr + sizeof(ptr)
++ptr
-------------Where does the sequence pointer occur in an expression?
At the end of a full expression and at the &&, || and ?: operators
At the end of full expression and at the end of = operator
At binary operators and at the end of a full expression
All of these
---------------What will be the output of the following program?
#include <stdio.h>
#include <stdlib.h>
union pw {
short int i;
char ch[2];
};
int putw(short int num, FILE *fp);
int main()
{
FILE *fp;
fp = fopen("Cprogram.tmp", "wb+");
if(fp == NULL) {
printf("Cannot open file\n");
exit(1);
}
putw(1025, fp);
fclose(fp);
return 0;
}

int putw(short int num, FILE *fp)


{
union pw word;
word.i = num;
putc(word.ch[0], fp);
return putc(word.ch[1], fp);
}

Compiler error
It will open the contents of Cprogram.tmp
It will print: Cannot open file
Runtime error
--------------If the value of a = 2 and z = 6, which one of the options represents the output
value C returned by the following statement?
C = (a *= 7) + (b = z = 8)/2 ;
18
Syntax error
17
Assignment error
----------------------What will be the output of the following program?
#include<stdio.h>
int main( )
{
int k = 10, j = k++ - 20 ;
printf ( "%d %d %d", j++, j++, j++, j++ ) ;
return 0;
}

9 -10

7 -8

-------------------What will be the output of the following program?


#include<stdio.h>
int main()
{
int *p;
*p = 50;
printf("%d",*p);
return 0;
}

Compiler error
50
It prints the address
Runtime error
------------Question Number 2
What will be the output of the following program?
#include<stdio.h>
void func(){
static int i=5;
char* a="gaurav";
if(i==0)
break;
printf("%c",a[i--]);
func();
}
int main()
{
func();
return 0;
}

varuagvaruagvaruag till stack overflows


Runtime error
Compiler error
varua
----------------------What will be the output of the following program?
#include<stdio.h>

int main()
{
int i = 8;
int k = 2;
switch(k){
case 1<<2:
printf("%d",i);
case 8>>2:
printf("%d",i);
default:
printf("%s"," Body of lies");
}
return 0;
}

Body of lies
8 8 Body of lies
Compiler error
8 Body of lies
----------------------A function can return __________
only one value
more then one, but finite values
any number of values
None of these
--------------------Question Number 5
What will be the output of the following program ?
#include<stdio.h>
int func1 (int a, int b)
{
return (a + b);
}
float func1(float a, float b)
{
return (a/b);
}
int func1(int a,int b,int c)
{
return (a - b - c);
}
int main()

{
int i = 10;
int j = 5;
printf("%d",func1(i,j,1));
return 0;
}

15
4
3
Compiler error
-----------------------Consider test1, test2, test3 as three functions. In which order will the functio
ns be called in the following expression?
a = test1() * test2() / test3() + test3;
test1, test2, test3
test2, test3, test1
test3, test2, test1
Compiler dependent
--------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int i=8,j=8;
while(i+1?--i:j++)
printf("%d ",i);
return 0;
}

1
8
1 2 3 4 5 6 7
7 6 5 4 3 2 1

------------------------------What does the code below declare?


int (*func)(char*, char*)
Pointer to function taking two char* as parameters and returning an int
Pointer to function taking two char* as parameters and returning an integer poin
ter
Function taking two char pointers and returning an integer pointer
None of these
------------------------------What will be the output of the following program?
#include<stdio.h>
void increment( int i )
{
i++;
}
int main()
{
for(int i=0; i<10; incr(i))
{
}
printf("i=%d\n", i);
return 0;
}

It runs in an infinite loop


Compiler error
10
9
-----------------------------What will be the output of the following program?
#include<stdio.h>
int main(){
FILE * fp = NULL;
char str[100]="abcdefghij";
fp = fopen("MyFile.txt","w");
while(!feof(fp))
{
fscanf(fp,"%s",str);
fprintf (fp, "[%-10.10s]\n",str);
}
fclose(fp);

return 0;
}

MyFile.txt will contain abcdefghij


Compiler error
Runtime error
Infinite loop
------------------What will be the value returned by the following function?
void func(int *ptr)
{
int i, output = 0;
for (i = 0; i < 5; ++i)
output += *(ptr + i);
return;
}

No value
The value of the 5th element of the array pointed by the pointer ptr
The sum of 5 elements of the array pointed by the pointer ptr
The address of the 5th element of the array pointed by the pointer ptr
-------------------------------------hat will be the output of the following program?
#include<stdio.h>
int main(){
int aVar[]={9,4,1,7,5};
int *pVar;
pVar=&aVar[3];
printf("%d",pVar[-1]);
return 0;
}

6
7
1

Compiler error
---------------What will be the output of the following program?
#include<stdio.h>
int main()
{
char *buffer = "Time Travel";
char *ptr = buffer;
ptr += 5;
printf( "%s\n", ptr );
printf( "%s\n", buffer );
return 0;
}

Travel
Time Travel
Time Travel
Travel
5ime Travel
5ime Travel
Travel
Travel
------------------What will be the output of the following program ?
#include<stdio.h>
int main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d", sizeof(str1), sizeof(str2));
return 0;
}

4 5
1 5
1 4
1 1
---------------------uestion Number 6
What will be the output of the following program ?

#include<stdio.h>
int main()
{
char *s = "ABCDEF";
char a[6]= {'A','B','C','D','E','F'};
printf("%d", strcmp(s,a));
return 0;
}

0
Compiler error
1
-1
------------------------What will be the output of the following program ?
#include<stdio.h>
int main()
{
int a=387;
char *ptr;
ptr=(char *)&a;
printf("%d ",*ptr);
return 0;
}

3
64
-125
Compiler error
------------------------What will be the output of the program below,if MyFile.txt contains abcdefghij?
#include <stdio.h>
int main()
{
FILE* fp = NULL;
unsigned char c;
fp = fopen("MyFile.txt","r");
while((c = getc(fp)) != EOF)
putchar(c);
fclose(fp);
return 0;

Stack overflow
Infinite loop
abcdefghij followed by infinite loop
Runtime error
----------------------------Which one of the following statements is correct?
strcmp ( s1 , s2 ) returns a number greater then 0 if s1 < s2
strcmp ( s1 , s2 ) returns 0 if s1 == s2
strcmp ( s1 , s2 ) returns a number less then 0 if s1 > s2
strcmp ( s1 , s2 ) returns 1 if s1 == s2
----------------------------What will be the output of the following program?
#include <stdio.h>
int main()
{
putchar(65);
putchar(10);
putchar(66);
putchar(10);
putchar(67);
putchar(10);
return 0;
}

65 10 66 10 67 10
Compiler error
A
B
C
ABCDEF
------------------------------Question Number 11

What will be the output of the following program?


#include <stdio.h>
fun(const int p)
{
int *ptr = &p;
printf("%d",*(ptr));
printf("%d",*(ptr-1));
}
int main()
{
int arr[]={1,2,3,4,5};
fun(arr[1]);
return 0;
}

Runtime error
2 1
2 garbage
Compiler error
-----------------------------------Which is the correct method of opening a file for writing as binary file?
FILE *f = fwrite("test.bin", "b");
FILE *f = fopenb("test.bin", "w");
FILE *f = fwriteb("test.bin");
FILE *f = fopen("test.bin", "wb");
-------------------------------------Which is the correct method of opening a file for writing as binary file?
FILE *f = fwrite("test.bin", "b");
FILE *f = fopenb("test.bin", "w");
FILE *f = fwriteb("test.bin");
FILE *f = fopen("test.bin", "wb");
-----------------------------------------What is the purpose of r+, in function fopen( ) used in the following program?
#include<stdio.h>

int main( )
{
FILE *fp ;
fp = fopen ( "NOTES.TXT", "r+" ) ;
return 0;
}

It reads the existing contents and then overwrites new contents thus modifying c
ontents of the file
It overwrites contents of an existing file
It reads existing contents and then appends the new contents to the end of file
but doesn t modify the file
It reads existing contents of a file
-------------------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"String");
strcpy(p2,"Array");
strcat(p1,p2);
printf("%s",p1);
return 0;
}

NULL
StringArray
Compiler error
None of these
--------------------------------------EXPERT LEVEL
What will be the output of the following program?
#include<stdio.h>
enum day{ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY};
int main()

{
enum day today;
for(today=SUNDAY; today<=SATURDAY; today++)
printf("%d ",today);
return 0;
}

Compiler error
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
0
0 1 2 3 4 5 6
------------------------------------What will be the output of the following program?
#include<stdio.h>
union union_tag{
union in_union{
int i;
char * nickname;
}b;
int a;
char * name;
};
int main()
{
union union_tag x = {12};
printf("%d",x.b.i);
return 0;
}

Compiler error
12
Garbage
Nesting of union leads to unpredictable results
-------------------------What will be the output of the following program?
#include<stdio.h>
#define sdef struct s *
struct s{int x;char y[2];};
int main()
{
sdef sobj1,sobj2;
sobj1->x=10;sobj1->y[0]='a';

sobj1->y[0]='b';sobj2=sobj1;
printf("%d%c%c",sobj2->x, sobj2->y[0],sobj2->y[1]);
return 0;
}

Runtime error
Compiler warning
Compiler error
10ab
------------------------------Which one of the following is not a user-defined data type?
struct book
{
char name[10] ;
float price ;
int pages ;
};

long int a = 235L ;


enum day { Sun, Mon, Tue, Wed } ;
All of these
-----------------------------What will be the output of the following program?
#include<stdio.h>
union union_tag{
int a;
char *name;
};
int main()
{
union union_tag x;
x.a = 26;
x.name = "Bob";
printf("%s",x.a);
return 0;
}

Bob
Garbage value

26
Compiler error
-----------------------------What will be the output of the following program?
struct Adv{
int p;
float q;
long double *r;
};
void main(){
struct Adv aList[10];
clrscr();
printf("%d",sizeof aList);
getch();
}

10
Compiler dependent
80
100
--------------------------------What will be the output of the following program?
#include<stdio.h>
int main ( )
{
int i = 3 , j=0 ,ii;
j = add ( ++i) ;
printf ( "i =%d j = %d",i, j ) ;
return 0;
}
add ( int ii )
{
ii++ ;
printf ( "ii = %d \n" , ii ) ;
return 0;
}

Compiler error
ii = 5
i =4 j = 0

ii = 3
i =3 j = 0
ii = 5
i =3 j = 0
---------------------------------What will the following program do?
binary(int n)
{
if(n==0)
return;
else{
binary(n/2);
printf("%d",(n%2));
}
}

It will lead to an infinite loop


Prints the even bits of a decimal number
Prints the binary representation of a decimal number
Prints the odd bits of a decimal number
---------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
void func(int n)
{
if(n==0)
{
printf("%d",n);
return ;
}
else
while(n!=0)
{
printf("%d",(n%2));
n=n/2;
}
}
return 0;
}

It prints the even bits of the number

It prints the binary representation of the number


It prints the odd bits of the number
None of these
-------------------What will be the output of the following program?
void main( )
{
int i = 138, a = 138, k ;
k = fun ( !++i, !++a ) ;
printf ( "%d %d %d", i, a, k ) ;
}
fun( int j, int b )
{
int c ;
c = j + b ;
return ( c ) ;
}

139 139 276


138 138 0
139 139 0
138 138 276
----------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int i=5;
do
{
printf("%d", i);
}
while(i--);
return 0;
}

5 4 3 2 1 0
5 4 3 2 1

4 3 2 1 0
Compiler error
---------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int i=255, j=255;
i>>2;
i<<2;
if(i<j)
printf("Condition 1");
else
printf("Condition 1");
return 0;
}

Condition 1
Condition 2
Compiler error
None of these
---------------------------What will be the output of the following program?
#include<stdio.h>
void fun(char *a)
{
char * b = "C unleashed";
b = a;
}
int main()
{
char* a;
fun(a);
printf("%d",*a);
return 0;
}

It will print some address


C unleashed
Runtime error

Compiler error
-----------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int i=1;
if(!i)
printf("It is up\n");
else
{
i=0;
printf("It is down\n");
main();
}
return 0;
}

It is down
It is up
It is up
It is down
It is down till stack overflow
None of these
-------------------------What will be the output of the following program?
void main()
{
int i=1;
switch(i)
{
lab:
case 0:
printf("%d", i);
break;
case 1:
++i;
printf("%d", i);
goto lab;
}
}

2 1
Compiler error

2 2
1 2
-------------------------What will be the output of the following program?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15

func(int *a);
int main()
{
const int *i;
int a = 10;
i = &a;
func(i);
printf("%d",*i);
getch();
}
func(int *a)
{
a++;
*a = 100;
}

100
Error in line 07
Error in line 07 & 13
10
-----------------------------What will be the output of the following program?
#include<stdio.h>
char* func()
{
char str[10] = "Take Care";
return str;
}
int main()
{
char* str1 = func();
printf("%s", str1);
return 0;
}

Take Care
Compiler error

Undefined value
None of these
-------------------What will be the output of the following program?
#include<stdio.h>
int main(){
char b,c;
for(printf("a\n");
printf("%c\n",b<c?'b':'c');
printf("c\n"));
printf("\n");
return 0;
}

bca
Compiler error
Infinite loop of bca
Infinite loop of c
-----------------------Point out the error if any, in the following code snippet?
#include <stdio.h>
int main()
{
int day,year;
char month[12];
clrscr();
scanf("%d %s %d",&day,month,&year);
printf("%d %s %d",day,month,year);
getch();
return 0;
}
Consider the input as: 23

Jan

83

Erroneous scanning of the month


Format specifiers should not have blank space
Output would be 23 garbage garbage
Output would be 23 Jan 83
-----------------------------What will be the output of the following program?

#include <stdio.h>
char *someFun()
{
char *temp = "local string";
return temp;
}
int main()
{
puts(someFun());
return 0;
}

Runtime error
Compiler error
local string
Undefined
----------------------------Consider the following two-dimensional array:
int twoarray[4][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Select the correct option that gives out the values of the following array eleme
nts.
twoarray[1][1], twoarray[2][0], twoarray[3][2], twoarray[0][2]
5, 7, 12, 1
5, 12, 7 , 3
5, 7, 12, 3
6, 9, 10, 2
------------------------------------What will be the output of the following program?
#include<stdio.h>
#define putchar (c) printf("%c",c)
int main()
{
char s='c';
putchar (s);
return 0;
}

Compiler error
99
Runtime error
C
--------------------------------What will be the output of the following program?
#include<stdio.h>
void print(int *b)
{
int i, j;
for(i=0; i<2; i++)
{
for(j=0; j<2; j++)
{
printf("%d ", *(b+i*2+j));
}
}
}
int main()
{
int a[2][2] = {1,2,3,4};
print(a);
return 0;
}

4 3 2 1
1 2 3 4
Compiler error
Garbage values
----------------------What will the content of Tree.dat file in the following program?
#include <stdio.h>
int main()
{
FILE *fp;
fp=fopen("Tree.dat","w");
fprintf(fp, "Root");
fclose(fp);
fp=fopen("Tree.dat","w");
fprintf(fp, "Leaf");
fclose(fp);
return 0;
}

RootLeaf
Root
Leaf
No Content
---------------------------Which one of the following statements represent a correct and safe declaration o
f a NULL pointer?
typedef((void *)0) NULL;
typedef NULL(char *)0;
#define NULL((void *)0)
None of these
---------------------------------Select the function which does not generate file names that can be safely used f
or a temporary file.
char *tmpname_r(char *s)
char *tempname r(const char *dir, const char *pfx)
char *tmpname(char *s)
char *tempname(const char *dir, const char *pfx)
-------------------------------------What will be the output of function below in ideal realtime situation?
int func(volatile int *ptr){
int x,y;x=*ptr;y=*ptr;
return x*y;}

Square of the value stored at ptr


Will depend on the program that uses this function
It will never return square of value stored at ptr

Compilation warning
--------------------------------What will be the output of the following program?
#include <stdio.h>
#define BUFSIZE 1024
void usage(char *cmd)
{
printf("Usage: %s <file to read with complete path>\n", cmd);
printf("If your file is at /home/Cprogramming/documents/names.txt,
then the command will be: \n");
printf("%s /home/ Cprogramming /documents/names.txt\n", cmd);
}
int main(int argc, char *argv[])
{
FILE *fp;
if (argc < 2)
{
usage(argv[0]);
exit(0);
}
fp = fopen(argv[1], "r");
if (fp == NULL)
{
usage(argv[0]);
exit(0);
}
printf("Contents of %s are: \n", argv[1]);
while (!feof(fp))
{
char buf[BUFSIZE] = {0};
fread(buf, sizeof(char), BUFSIZE, fp);
printf("%s", buf);
}
printf("End of the file\n");
fclose(fp);
return 0;
}

Compiler error
Runtime error
No output

None of these
-----------------------------Consider the following program:
#include <alloc.h>
int main( )
{
int **p , i ;
p = ( int ** ) malloc ( sizeof ( int * ) * 3 ) ;
for ( i = 0 ; I < 3 ; i++ )
p[ i ] = (int * ) malloc ( 4*sizeof ( int ) ) ;
return 0;
}
How would you free the memory allocated by above program?
for ( i = 0 ; i < 3; i ++) free ( p[i] ) ;
for ( i = 0 ; i < 4 ; i++ ) free ( p[i] ) ; free ( p ) ;
for( i = 0 ; i < 3 ;i++ ) free ( p[i] ) ; free ( p ) ;
free ( **p ) ;
-------------------------------------------What will be the output of the following program?
#include<stdio.h>
open(char *a,FILE **ptr){
*ptr = fopen(a,"r");
}
int main()
{
char *c;
file *ptr;
open("C:\\test.txt",*ptr);
while (fgets(c,100,ptr)!=NULL){
puts(c);
}
fclose(ptr);
getch();
return 0;
}

It will print the last line of the file twice while printing the contents of the
file
It will run into an infinite loop
Compiler error
It will print the contents of the file till it encounters the EOF

---------------------------------------------------What will be the output of the following program?


#include <stdio.h>
int main( )
{
float *f; char *c ;
f = malloc ( 4 ) ;
*f = 10.45 ;
*c = 'A' ;
printf ( "%f %c", *f, *c ) ;
return 0;
}

10.450000 A
10.45
Garbage value A
10 65
------------------------------------What will be the output of the following program?
#include<stdio.h>
int f(){
static int i;
i--;
return i;
}
int main()
{
int a = 10;
a=f();
printf("%d",a);
return 0;
}

-1
1
10
Garbage value
------------------------------What will be the output of the following program?
#include<stdio.h>
int main()

{
int arr[] = {1,2,3,4,5,6};
static int i;
for(;i<3;i++)
printf("%d ",arr[arr[i]]++);
return 0;
}

2 4 5
3 5
Runtime error
Compiler error
--------------------------------What will be the output of the following program?
typedef struct { int a;short b; } sFile;
int main()
{
sFile sData ={0,0};
int d=1000;
short i=20;
FILE* fp=fopen("MyFile.dat", "wb");
if(1!=fwrite(&d,sizeof(d),1,fp)) return 1;
if(1!= fwrite(&i,sizeof(i),1,fp)) return 1;
fclose(fp);
fp = fopen("MyFile.dat","rb");
if(fread(&sData,sizeof(sData),1,fp))!= 1)
return 1;
fprintf(stdout,"%d",sData.a);
fclose(fp);
return 0;
}

fread returns error


Runtime error
2nd fwrite returns error
1000
-------------------------What is the equivalent pointer expression for referring the element a[i][j][k][l
]?

* ( * ( * ( a + i ) + j ) + k ) + l
* ( * ( * ( * ( a + i ) j ) k ) l )
* ( * ( * ( * ( a + i ) + j ) + k ) + l )
( a + i ) + j ) + k ) + l
-----------------------------What will be the output of the following program?
Assume numbers2.txt contains the following data
111 222 333
444 555 666
777 888 999
int main()
{
char c[10];
FILE *file;
file = fopen("numbers2.txt", "r");
if(file==NULL)
{
printf("Error: can't open file.\n");
return 1;
}
else
{
printf("File opened successfully. Contents:\n\n");
while(fgets(c, 10, file)!=NULL)
{
printf("String: %s", c);
}
printf("\n\nNow closing file...\n");
fclose(file);
return 0;
}
}

File opened successfully. Contents:


String: 111 222 String: 333
String: 444 555 String: 666
String: 777 888 String: 999
Now closing file
File opened successfully. Contents:
String: 111 222 3String: 333

String: 444 555 6String: 666


String: 777 888 9String: 999
Now closing file
Runtime error
File opened successfully. Contents:
String: 111 222 3String: 33
String: 444 555 6String: 66
String: 777 888 9String: 99
Now closing file
--------------------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int xArray[] = { 1, 4, 8, 5, 1, 4 };
int *ptr, yValue;
ptr = xArray + 4;
yValue = ptr - xArray;
printf("%d",yValue);
return 0;
}

4
4*size(int)
-3
0
-------------------------------------What will be the output of the following program?
#include<stdio.h>
#include<stdlib.h>
int main( )
{
unsigned char ch ;
FILE *fp ;
fp = fopen ( "trial.c", "r" ) ;
if ( !fp )
{
printf ( "Unable to open the file" ) ;
exit ( 0 ) ;
}
fclose ( fp ) ;
return 0;
}

Unable to open the file


Runtime error
Compiler error
Compiles successfully
------------------------What will be the output of the following program?
#include<stdio.h>
int main()
{
int *p = malloc(20);
memset(p,20,20);
printf("%d",p[2]);
return 0;
}

0
Garbage
20
None of these
-------------------------------

You might also like