2
Q:

What is the output of this C code?

       #include <stdio.h>
        void main()
        {
            int x = 1, z = 3;
            int y = x << 3;
            printf( "%dn", y );
        }

A) -2147483648 B) -1
C) Run time error D) 8

Answer:   D) 8



Explanation:
Subject: Programming
Q:

What will be output of following c code?

#include <stdio.h>
int main()

{
    int x=123;
    int i={
         printf("c" "++")
    };
    for(x=0;x<=i;x++){
         printf("%x ",x);
    }
    return 0;

}

Answer

Output: c++0 1 2 3

Explanation: First printf function will print: c++ and return 3 to variable i.For loop will execute three time and printf function will print 0, 1, 2 respectively.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

63 44514
Q:

What will be output of following c code?

#include <stdio.h>
int main()

{
    int i;
    for(i=10;i<=15;i++){
         while(i){
             do{
                 printf("%d ",1);
                 if(i>1)
                      continue;
             }while(0);
             break;
         }
    }
    return 0;
}

Answer

Output: 1 1 1 1 1 1
For loop will execute six times.


 


 


 


Note: continue keyword in do-while loop bring the program its while condition (while(0)) which is always false.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1686
Q:

What will be output of following program ?

#include
int main()

{

int a = 10;
void *p = &a;
int *ptr = p;
printf("%u",*ptr);
return 0;

}

A) 10 B) Address
C) 2 D) Compilation error
 
Answer & Explanation Answer: A) 10

Explanation:

Void pointer can hold address of any data type without type casting. Any pointer can hold void pointer without type casting.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 13390
Q:

What will be output of following program?


#include <stdio.h>
int main()

{
   void (*p)();
   int (*q)();
   int (*r)();
   p = clrscr;
   q = getch;
   r = puts;
  (*p)();
  (*r)("www.sawaal.com");
  (*q)();
  return 0;
}

A) NULL B) www.sawaal.com
C) Compilation error D) None of above
 
Answer & Explanation Answer: B) www.sawaal.com

Explanation:

p is pointer to function whose parameter is void and return type is also void. r and q is pointer to function whose parameter is void and return type is int . So they can hold the address of such function.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 22116
Q:

The output of the code below is

        #include <stdio.h>
        int *m()
        {
            int *p = 5;
            return p;
        }
        void main()
        {
            int *k = m();
            printf("%d", k);
        }

A) 5 B) Junk value
C) 0 D) Error
 
Answer & Explanation Answer: A) 5

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 10565
Q:

 What is the output of this C code? 

        #include <stdio.h>
        void m()
        {
            printf("hi");
        }
        void main()
        {
            m();
        }

A) hi B) Run time error
C) None D) Varies
 
Answer & Explanation Answer: A) hi

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

0 10121
Q:

The output of the code below is

       #include <stdio.h>
        void main()
        {
            int i = 0, k;
            if ( i == 0 )
                goto label;
                for ( k = 0;k < 3; k++ )
                {
                    printf( "hin" );
                    label: k = printf( "%03d", i );
                }
         }

A) 0 B) hi hi hi 0 0 0
C) 0 hi hi hi 0 0 0 D) 0 0 0
 
Answer & Explanation Answer: A) 0

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 13006
Q:

How many times i value is checked in the below code?

       #include <stdio.h>
        int main()
        {
            int i = 0;
            do {
                i++;
                printf( "In while loopn" );
            } while (i < 3);
        }

A) 2 B) 3
C) 4 D) 1
 
Answer & Explanation Answer: B) 3

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 15922