Alien head

C Programming

Attempted 0/11 Correct 0 Score 0

What will be the output of the following program if 'n' key is pressed after execution of program?
#include<stdio.h>
#include<process.h>
void main()
{char ch;
printf("enter Y/y to continue");
scanf("%c",&ch);
if(ch=='y' || ch=='Y')
printf("Yes");
else
exit(1);
}

Consider the letters written like A, B, C, V are the keys prssed by user. User can press any key, we have considered following keys has been prssed.

  1. Yes

  2. Exit from program

  3. Error: exit function should have prototype

  4. No

  5. None of these


Correct Option: B
Explanation:

As input to program is 'n'i.e. other than Y,y, it will exit from program

Which of the following functions have exactly same working?
(a) putch()
(b) putchar()
(c) puts()
(d) fputs()
(e) fputchar()

  1. b and c

  2. a, b and e

  3. d and e

  4. a, b, d and e

  5. all of these


Correct Option: B
Explanation:

The working of putch(), putchar() and fputchar() is same, they can print/output one character at a time.
e.g.
putch(‘A’);
putchar(‘B’);

fputchar(‘C’)
Output: ABC

Which of the following describes the function of strcmpi()?

  1. Compares two strings regardless of case

  2. Compares the portion of one string with portion of another string

  3. Compares the portion of one string with portion of another string regardless of case

  4. All of the above

  5. None of the above


Correct Option: A
Explanation:

strcmpi():Compares two strings without regard to case.

Which of the following is not true about while and do while loop?
(a) while loop is entry control and do-while is exit control.
(b) do-while must be executed atleast once and while loop may execute once or not.
(c) ‘;’ is given after while in both while and do-while loop.
(d) Condition is given in while statement in both while and do-while loop.

  1. b and d

  2. a, b and d

  3. only c

  4. all of these

  5. none of these


Correct Option: C
Explanation:

‘;’ is given after while in do-while loop whereas ‘;’ is not given after while in while loop

Which of the following case constants in switch-case is/are not allowed?
(a) case ‘S’: and case ‘s’:
(b) case a + b: and case a + 3:
(c) case i <= 20:
(d) case 7 - 3:
(e) case 3.14:

  1. only b

  2. b,c and e

  3. a and d

  4. all a,b,c,d and e

  5. none of the above


Correct Option: B
Explanation:

Following case statements are invalid:case a+b: and case a+3:case i<=20:case 3.14:Conditional expression, float constant and expressions having variables are not valid. So option 2 is correct answer.

What will be the output of following program code?
#include<stdio.h>
main()
{
int k; float j;
j=9.0/2; k=9/2.0;
printf(%dt%ft,k,j);
j=9/2; k=9/2;
printf(%dt%ft,k,j);
k=9.0/2.0; j=2/9.0;
printf(%dt%ft,k,j);
}

  1. 4.000000 4.500000 4.000000 4 0.222222 4

  2. 4 4.500000 4 4.000000 0.222222 4

  3. 4 4.500000 4 4.000000 4 0.222222

  4. 4 4 4 4 4 0.000000

  5. None of these


Correct Option: B
Explanation:

k=9/2.0=4, as k is integer type output will be an integer.
j=9.0/2=4.500000, as j is of type float the output will be in float.
k=9/2=4, as k is integer type output will be an integer.
j=9/2=4.000000
j=2/9.0=0.222222
k=9.0/2.0=4, as k is integer type output will be an integer.

What does the following program code do?
#include<stdio.h>
void main()
{FILE *f;char ch;
int noi=0;
f=open(“d.txt”,”r”);
while(1)
{ ch=fgetc(f);
if(f==EOF)
break;
if(ch==’ ‘)
noi++’;}
fclose(f);
printf(“No. of …….=%d”,noi);}

  1. Counts total number of character in file d.txt

  2. Counts number of blanks in file d.txt

  3. Counts number of tabs in file d.txt

  4. Counts number of lines in file d.txt

  5. Counts total number of characters in file ‘C’ source file


Correct Option: B
Explanation:

The ‘ ‘ counts the blanks in file opened.

Which of the following is not true about loops in ‘C’?

  1. Working of while and do-while loop is same.

  2. while(1) is infinite loop and exit() can be written to come outside the loop.

  3. for(;;) implements an infinite loop.

  4. A break statement takes the execution control out of the loop.

  5. A continue statement skips the execution of the statements after the control to the beginning of the loop.


Correct Option: A
Explanation:

Working of while and do-while loop is not same. As while is entry control and do-while is exit control.

Which of the following structure declarations and structure variable's syntax is correct?

  1. struct test
    { int k; char ch; };
    struct test t1,t2;

  2. struct test
    { int k; char ch; }t1,t2;

  3. struct
    { int k; char ch; }t1,t2;

  4. struct test
    { int k; char ch; };
    test t1,t2;

  5. struct test
    { int k; char ch; };
    struct test t[4];


Correct Option: D
Explanation:

struct test
{ int k; char ch; };
test t1,t2;
the above declaration is wrong and it will show an error. As keyword struct is not written before test while creating variables of type test.

Which is the correct format for type casting in C? (Consider the following program code.)
include<stdio.h>
main()
{int x=100,y=7;
float z;z=……..;
prinf(“z=%f”,z);}

  1. float(x/y)

  2. (float)x/y

  3. (float)(x/y)

  4. x/y

  5. none of these


Correct Option: B
Explanation:

The correct format for type casting in C is (data-type)values i.e. (float)x/y

What will be the output of following program code?
#include<stdio.h>
main()
{int a=10,b=12,c=0;
if(!(a>5&&c))
{ printf(%d,a!=6&&b>5);
printf(%d,a==10||b<15&&c<1); }
else
printf(If expression is wrong);}

  1. 11

  2. 10

  3. 01

  4. 00

  5. 'If' expression is wrong.


Correct Option: A
Explanation:

a=10,b=12,c=0(!(a>5&&c))=>!(10>5 && 0)=>!(1 &&0)=>!0=>1
If condition is true as we get ‘1’ in above expression.a!=6&&b>5=>10!=6 && 12>5 =>1 && 1 =>1a==10||b<15&&c<1 =>10==10 || 12<15 && 0<1 =>1 || 1 && 1=> 1
So option 1 is correct answer.

+ View questions