Showing posts with label mcq questions. Show all posts
Showing posts with label mcq questions. Show all posts

Wednesday, 8 November 2017

Control Structures Questions in C


1.
What will be the output of following program ?

#include
void main()
{
    if(!printf(""))
        printf("Okkk");
    else
        printf("Hiii");
}

A. okkk
B. Hiii
C. Error
D. None

Answer: A
---------------------------------------------------------------------------------------------

2.
What will be the output of following program ?

#include
int main()
{
    int a=10;
    if(10L == a)
        printf("10L");
    else if(10==a)
        printf("10");
    else
        printf("0");
    return 0;
}

A. 10
B. 10L
C. 10L10
D. ERROR

Answer: B
----------------------------------------------------------------------------------------------

3.
Find the output?

#include
int main()
{
    int pn=100;
    if(pn>20)
        if(pn<20 font="">
            printf("Heyyyyy");
    else
        printf("Hiiiii");
    return 0;
}

A. No output
B. Hiiiii
C. Heyyyyy
D. HeyyyyyHiiiii

Answer: B
---------------------------------------------------------------------------------------

4.
Find the output?

#include
#define TRUE 1
int main()
{
    if(TRUE)
        printf("1");
        printf("2");
    else
        printf("3");
        printf("4");
    return 0;
}

A. ERROR
B. 1
C. 12
D. 2

Answer: A
-----------------------------------------------------------------------------------------

5.
Find the output?

#include
int main()
{
    int a=10;
    if(a==10)
    {
        printf("Hello...");
        break;
        printf("Ok");
    }
    else
    {
        printf("Hii");
    }
    return 0;
}

A. Hello...
B. Hello...OK
C. OK
D. ERROR

Answer: D
----------------------------------------------------------------------------------

6. 


What will be output when you will execute following c code?

#define True 5==5
#include
void main(){
    if(.001-0.1f)
         printf("David Beckham");
    else if(True)
         printf("Ronaldinho");
    else
        printf("Cristiano Ronaldo");
}

Choose an option:

A. David Beckham
B. Ronaldinho
C. Cristiano Ronaldo
D. Warning: Condition is always true
E. Warning: Unreachable code

Answer: A,D,E
--------------------------------------------------------------------------------------------

7.

What will be output when you will execute following c code?

#include
void main(){
    int a=100;
    if(a>10)
         printf("M.S. Dhoni");
    else if(a>20)
         printf("M.E.K Hussey");
    else if(a>30)
           printf("A.B. de villiers");
}

Choose all that apply:

A. M.S. Dhoni
B. A.B. de villiers
C. M.S Dhoni
     M.E.K Hussey
     A.B. de Villiers
D. Compilation error: More than one conditions are true
E. None

Answer: A
-------------------------------------------------------------------------------------

8.


What will be output when you will execute following c code?

#include
void main(){
    if(sizeof(void))
         printf("M. Muralilidaran");
    else
         printf("Harbhajan Singh");
}

Choose an option:

A. M. Muralilidaran
BHarbhajan Singh
C. Warning: Condition is always false
D. Compilation error
E. None

Answer: D
------------------------------------------------
More Imp Topics:

Data Types       
Operators
Pointers
Array
Preprocessor
Structures

Find Output Array Questions

Simple Array Questions in C
Yes/No Array Questions

-------------------------------------------------------------------------------------------------------
1. 
Predict the output?


public class Main {
    public static void main(String args[]) {
       int arr[] = {10, 20, 30, 40, 50};
       for(int i=0; i < arr.length; i++)
       {
             System.out.print(" " + arr[i]);              
       }
    }
}


A. 10 20 30 40 50
B. Compiler Error
C. 10 20 30 40
D. None

Answer: A
------------------------------------------------------------------------------------------------------------------------

2. 

class Test {
   public static void main(String args[]) {
     int arr[] = new int[2];  
     System.out.println(arr[0]);
     System.out.println(arr[1]);
   }
}

A. 0
     0
B. Garbage value
    Garbage value
C. Compiler
D.Exception

Answer: A

-----------------------------------------------------------------------------------------------------------------
3.
public class Main {
    public static void main(String args[]) {
        int arr[][] = new int[4][];
        arr[0] = new int[1];
        arr[1] = new int[2];
        arr[2] = new int[3];
        arr[3] = new int[4];
  
        int i, j, k = 0;
        for (i = 0; i < 4; i++) {
            for (j = 0; j < i + 1; j++) {
                arr[i][j] = k;
                k++;
            }
        }
        for (i = 0; i < 4; i++) {
            for (j = 0; j < i + 1; j++) {
                System.out.print(" " + arr[i][j]);
                k++;
            }
            System.out.println();
        }
    }

A. 0
    1 2
    3 4 5
    6 7 8 9

B. Compiler Error
C. 0
     0 0
     0 0 0
     0 0 0 0
D. 9
     7 8
     4 5 6
     0 1 2 3 

Answer: A
-----------------------------------------------------------------------------------------------------------------

4.
Output of following Java program?

int main()
{
    static int a[2][2] = {1, 2, 3, 4};
    int i, j;
    static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};
    for(i=0; i<2 font="" i="">
    {
        for(j=0; j<2 font="" j="">
        {
            printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i), 
                                    *(*(i+p)+j), *(*(p+j)+i));
        }
    }
    return 0;
}

A. 1, 1, 1, 1
     2, 3, 2, 3
     3, 2, 3, 2
     4, 4, 4, 4

B. 1, 2, 1, 2
     2, 3, 2, 3
     3, 4, 3, 4
     4, 2, 4, 2
C. 1, 1, 1, 1
     2, 2, 2, 2
     2, 2, 2, 2
     3, 3, 3, 3
D. 1, 2, 3, 4
     2, 3, 4, 1
     3, 4, 1, 2
     4, 1, 2, 3

Answer: C
-----------------------------------------------------------------------------------------------------------
5.

What will be the output of the program ?

#include
void fun(int **p);

int main()
{
    int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};
    int *ptr;
    ptr = &a[0][0];
    fun(&ptr);
    return 0;
}
void fun(int **p)
{
    printf("%d\n", **p);
}


A. 1
B. 2
C. 3
D. 4

Answer: A

------------------------------------------------------------------------------------------------------------

More Array Topics:


100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...