Advertisements

Search results for while

Example:[1]

            What is the output of the following program?
#include <stdio.h>
int func(int );
void main()
{
  int d = 1,res;
  res = func(d);
  printf("%d\n", res);
} 
int func(int x)
{
  do
  {
    res += x;
    x++;  
  }while(x <= 5);
  return res;
}

          
Option A:

            16
            
Option B:

            13
            
Option C:

            15
            
Option D:

            Compile error
            
Correct Answer: option D
Example:[2]

            What would be the output of following program?
#include <stdio.h>
int func(int );
int main()
{
    int res;
    res = func(123);
    printf("%d\n", res);
    return 0;
}
int func(int num)
{
    int s = 0,rem;
    while(num > 9)
    {
        rem = num%10;
        s += rem;
        num /= 10;
    }
    s += num;
    return s;
}
          
Option A:

            2
            
Option B:

            1
            
Option C:

            6
            
Option D:

            3
            
Correct Answer: option C
Example:[3]

            What is the output of the following program?
#include <stdio.h>
int func(int );
int main()
{
    int res;
    res = func(123);
    printf("%d\n", res);
    return 0;
}
int func(int num)
{
    int rem;
    while(num > 9)
    {
        rem = num%10;
        num /= 10;
    }
    return num;
}
          
Option A:

            6
            
Option B:

            1
            
Option C:

            2
            
Option D:

            3
            
Correct Answer: option B
Example:[4]

            What is the output of the following program?
#include <stdio.h>
int func(int ,int );
int main()
{
    int res;
    res = func(2,6);
    printf("%d\n", res);
    return 0;
}
int func(int n1,int n2)
{
	int i,r = 0;
	do{
		r += n1;
        n1++;
	}while(n1 < n2);
    return r;
}
          
Option A:

            14
            
Option B:

            20
            
Option C:

            8
            
Option D:

            12
            
Correct Answer: option A
Example:[5]

            What is the output of the following program?
#include <stdio.h>
int main ()
{
        char s[] = "Mbed";
        int i = 0;
        while(s[i] != 0)
        {
                printf("%c %c %c\n", s[i], *(s + i), *(i + s));
                i++;
        }
        return 0;
}
          
Option A:

            b  b  b
e  e  e
d  d  d
M  M  M
            
Option B:

            M  M  M
b  b  b
e  e  e
d  d  d
            
Option C:

            M  M  M
b  b  b
d  d  d
e  e  e
            
Option D:

            M  M  M
e  e  e
b  b  b
d  d  d
            
Correct Answer: option B

 Search Links


 Popular C search MCQs


 Popular C search examples