C/C / Sample Test,Sample questions

Question:
Comment on the output of this C code?

int main()
{
char c;
int i = 0;
FILE *file;
file = fopen("test.txt", "w+");
fprintf(file, "%c", 'a');
fprintf(file, "%c", -1);
fprintf(file, "%c", 'b');
fclose(file);
file = fopen("test.txt", "r");
while ((c = fgetc(file)) != -1)
printf("%c", c);
return 0;
}

1.a

2.Infinite loop

3.Depends on what fgetc returns

4.Depends on the compiler

Posted Date:-2022-03-21 07:57:29


Question:
Comment on the output of this C code?

int main()
{
float f1 = 0.1;
if (f1 == 0.1)
printf("equal
");
else
printf("not equal
");
}

1.equal

2.not equal

3.Output depends on compiler

4.None of the mentioned

Posted Date:-2022-03-21 07:58:57


Question:
Comment on the output of this C code?

int main()
{
float f1 = 0.1;
if (f1 == 0.1f)
printf("equal
");
else
printf("not equal
");
}

1.equal

2. not equal

3.Output depends on compiler

4.None of the mentioned

Posted Date:-2022-03-21 08:35:43


Question:
Comment on the output of this C code?

int main()
{
int a[5] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 5; i++)
if ((char)a[i] == '5')
printf("%d
", a[i]);
else
printf("FAIL
");
}

1.The compiler will flag an error

2.Program will compile and print the output 5

3.Program will compile and print the ASCII value of 5

4.Program will compile and print FAIL for 5 times

Posted Date:-2022-03-21 07:48:52


Question:
The format identifier '%i' is also used for _____ data type?

1.char

2.int

3.float

4.double

Posted Date:-2022-03-21 07:49:21


Question:
What is short int in C programming?

1.Basic data type of C

2.Qualifier

3.short is the qualifier and int is the basic datatype

4.All of the mentioned.

Posted Date:-2022-03-21 07:57:59


Question:
What is the output of the following C code(on a 64 bit machine)?

union Sti
{
int nu;
char m;
};
int main()
{
union Sti s;
printf("%d", sizeof(s));
return 0;
}

1.8

2.5

3.4

4.9

Posted Date:-2022-03-21 08:39:10


Question:
What is the output of this C code (on a 32-bit machine)?

int main()
{
int x = 10000;
double y = 56;
int *p = &x;
double *q = &y;
printf("p and q are %d and %d", sizeof(p), sizeof(q));
return 0;
}

1.p and q are 4 and 4

2.p and q are 4 and 8

3.Compiler error

4. p and q are 2 and 8

Posted Date:-2022-03-21 08:37:17


Question:
What is the output of this C code?

int main()
{
char chr;
chr = 128;
printf("%d
", chr);
return 0;
}

1.128

2.- 126

3. Depends on the compiler

4.None of the mentioned

Posted Date:-2022-03-21 07:55:37


Question:
What is the output of this C code?

int main()
{
float x = 'a';
printf("%f", x);
return 0;
}

1.a

2.run time error

3.a.0000000

4.97.000000

Posted Date:-2022-03-21 08:40:18


Question:
What is the size of an int data type?

1.4 Bytes

2.8 Bytes

3.Depends on the system/compiler

4.Cannot be determined.

Posted Date:-2022-03-21 07:53:47


Question:
Which data type is most suitable for storing a number 65000 in a 32-bit system?

1.short

2.int

3.long

4.double

Posted Date:-2022-03-21 07:50:26


Question:
Which is correct with respect to size of the datatypes?

1. char > int > float

2.int > char > float

3.char < int < double

4.double > char > int

Posted Date:-2022-03-21 08:38:14


Question:
Which of the datatypes have size that is variable?

1.int

2. struct

3.float

4.double

Posted Date:-2022-03-21 08:41:18


Question:
Which of the following is a User-defined data type?

1.typedef int Boolean;

2.typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;

3.struct {char name[10], int age};

4.All of the mentioned

Posted Date:-2022-03-21 07:52:54


More MCQS

  1. help4info.com
  2. help4info.com
  3. help4info.com
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!