2
Q:

If the following program (myprog) is run from the command line as 

myprog 1 2 3 

what would be the output?

main(int argc, char *argv[])

{

    int i, j = 0;

    for (i = 0; i < argc ; i++)

           j = j + atoi ( argv[i]);

    printf ("%d", j);

}

A) 123 B) 6
C) Error D) "123"

Answer:   B) 6



Explanation:

When atoi() tries to convert argv[0] to a number it cannot do so (argv[0] being a file name) and hence returns a zero.

Subject: Programming
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 22117
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
Q:

What is the output of this C code?

   #include <stdio.h>
    int main()
    {
        int a = 1, b = 1;
        switch (a)
        {
        case a*b:
            printf("yes ");
        case a-b:
            printf("non");
            break;
        }
    }

A) yes B) no
C) Compile time error D) yes no
 
Answer & Explanation Answer: C) Compile time error

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

7 19416