C Input and Output

Last Updated :
Discuss
Comments

Question 1

What is the output of the below code 

int i = 0;

while(i<n){

if(i%2)break;

i++;}

cout<<i;

  • A

    1

  • B

    0

  • C

    n

  • D

    n-1

Question 2

Consider the following C program.
 

C
#include <stdio.h>

int main()
{
    int i, j, count;
    count = 0;
    i = 0;
    
    for (j = -3; j <= 3; j++)
    {
        if ((j >= 0) && (i++))
        {
            count = count + j;
        }
    }
    
    count = count + i;
    printf("%d", count);
    
    return 0;
}

Which one of the following options is correct?

  • A

    The program will not compile successfully

  • B

    The program will compile successfully and output 10 when executed

  • C

    The program will compile successfully and output 8 when executed

  • D

    The program will compile successfully and output 13 when executed

Question 3

Consider the following ANSI C function:

int SimpleFunction(int Y[], int n, int x)
{
int total = Y[0], loopIndex;
for (loopIndex=1; loopIndex<=n-1; loopIndex++)
total=x*total +Y[loopIndex];
return total;
}

Let Z be an array of 10 elements with Z[i]=1, for all i such that 0 <= i <= 9. The value returned by SimpleFunction(Z,10,2) is __________ .

  • A

    1023

  • B

    1024

  • C

    2047

  • D

    511

Question 4

Consider the following ANSI C program.

#include < stdio.h >
int main( )
{
int arr[4][5];
int i, j;
for (i=0; i<4; i++)
{
for (j=0; j<5; j++)
{
arr[i][j] = 10 * i + j;
}
}
printf("%d", *(arr[1]+9));
return 0;
}

What is the output of the above program?

  • A

    14

  • B

    20

  • C

    24

  • D

    30

Question 5

Consider the following ANSI C function:

int SomeFunction (int x, int y)
{
if ((x==1) || (y==1)) return 1;
if (x==y) return x;
if (x > y) return SomeFunction(x-y, y);
if (y > x) return SomeFunction (x, y-x);

}

The value returned by SomeFunction (15, 255) is __________ .

  • A

    15

  • B

    1275

  • C

    30

  • D

    255

Question 6

Consider the following ANSI C program

#include 
int foo(int x, int y, int q)
{
if ((x<=0) && (y<=0))
return q;
if (x<=0)
return foo(x, y-q, q);
if (y<=0)
return foo(x-q, y, q);
return foo(x, y-q, q) + foo(x-q, y, q);
}
int main( )
{
int r = foo(15, 15, 10);
printf(“%d”, r);
return 0;
}

The output of the program upon execution is _________ .

  • A

    60

  • B

    10

  • C

    15

  • D

    50

Question 7

Consider the following C program.

C
#include <stdio.h>
struct Ournode {
  char x, y, z;
};

int main() {
  struct Ournode p = {'1', '0', 'a' + 2};
  struct Ournode *q = &p;
  printf("%c, %c", *((char *)q + 1), *((char *)q + 2));
  return 0;
}

The output of this program is:

  • A

    0, c

  • B

    0, a+2

  • C

    '0', 'a+2'

  • D

    '0', 'c'

Question 8

Predict the output of following program? C
#include "stdio.h"
int main()
{
    char arr[100];
    printf("%d", scanf("%s", arr));
    /* Suppose that input value given
        for above scanf is "GeeksQuiz" */
    return 1;
}
  • A
    9
  • B
    1
  • C
    10
  • D
    100

Question 9

fggbb

  • A

    a

    C++
    #include <stdio.h>
    int compute() {
        static int k = 1;
        k = k * 3 - 1;
        return k;
    }
    int main() {
        int x, y, z;
        x = compute();
        y = x + compute();
        z = compute() - y;
        printf("%d\n", x + y * z);
        return 0;
    }
    


  • B

    s4

  • C

    c

  • D

    g

Question 10

Predict output of the following program 

C
#include <stdio.h>
int main()
{
   printf("\new_c_question\b\r");
   printf("geeksforgeeks"); 
   getchar();
   return 0;
}
  • A

    ew_c_question
    geeksforgeeks
     

  • B

    new_c_ques
    geeksforgeeks
     

  • C


    geeksforgeeks
     

  • D

    Depends on terminal configuration

Tags:

There are 38 questions to complete.

Take a part in the ongoing discussion