C Program find Output code snippet SET - 9


1.
How many times the while loop will get executed if a short int is 2 byte wide?
#include<stdio.h>
int main()
{
    int j=1;
    while(j <= 255)
    {
        printf("%c %d\n", j, j);
        j++;
    }
    return 0;
}
A.
Infinite times
B.
255 times
C.
256 times
D.
254 times
Workspace

2.
Which of the following errors would be reported by the compiler on compiling the program given below?
#include<stdio.h>
int main()
{
    int a = 5;
    switch(a)
    {
    case 1:
    printf("First");

    case 2:
    printf("Second");

    case 3 + 2:
    printf("Third");

    case 5:
    printf("Final");
    break;

    }
    return 0;
}
A.
There is no break statement in each case.
B.
Expression as in case 3 + 2 is not allowed.
C.
Duplicate case case 5:
D.
No error will be reported.
Workspace

3.
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
    int P = 10;
    switch(P)
    {
       case 10:
       printf("Case 1");

       case 20:
       printf("Case 2");
       break;

       case P:
       printf("Case 2");
       break;
    }
    return 0;
}
A.
Error: No default value is specified
B.
Error: Constant expression required at line case P: 
C.
Error: There is no break statement in each case.
D.
No error will be reported.
Workspace

4.
What will be the output of the program?
#include<stdio.h>
int main()
{
    int i=2;
    printf("%d, %d\n", ++i, ++i);
    return 0;
}
A.
3, 4
B.
4, 3
C.
4, 4
D.
Output may vary from compiler to compiler
Workspace

5.
In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators
A.
True
B.
False
Workspace

6.
What is the notation for following functions?
1.  int f(int a, float b)
    {
        /* Some code */
    }

2.  int f(a, b)
    int a; float b;
    {
        /* Some code */
    }
A.
1. KR Notation
2. ANSI Notation
B.
1. Pre ANSI C Notation
2. KR Notation
C.
1. ANSI Notation
2. KR Notation
D.
1. ANSI Notation
2. Pre ANSI Notation
Workspace

7.
How many times the program will print "IndiaBIX" ?
#include<stdio.h>

int main()
{
    printf("IndiaBIX");
    main();
    return 0;
}
A.
Infinite times
B.
32767 times
C.
65535 times
D.
Till stack overflows
Workspace

8.
What will be the output of the program?
#include<stdio.h>
#define SQR(x)(x*x)

int main()
{
    int a, b=3;
    a = SQR(b+2);
    printf("%d\n", a);
    return 0;
}
A.
25
B.
11
C.
Error
D.
Garbage value
Workspace

9.
A preprocessor directive is a message from programmer to the preprocessor.
A.
True
B.
False
Workspace

10.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char *p;
    p="hello";
    printf("%s\n", *&*&p);
    return 0;
}
A.
llo
B.
hello
C.
ello
D.
h
Workspace

11.
How will you free the allocated memory ?
A.
remove(var-name);
B.
free(var-name);
C.
delete(var-name);
D.
dalloc(var-name);
Workspace

12.
In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?
A.
"I am a boy\r\n\0"
B.
"I am a boy\r\0"
C.
"I am a boy\n\0"
D.
"I am a boy"
Workspace

13.
Which files will get closed through the fclose() in the following program?
#include<stdio.h>

int main()
{
    FILE *fs, *ft, *fp;
    fp = fopen("A.C", "r");
    fs = fopen("B.C", "r");
    ft = fopen("C.C", "r");
    fclose(fp, fs, ft);
    return 0;
}
A.
"A.C" "B.C" "C.C"
B.
"B.C" "C.C"
C.
"A.C"
D.
Error in fclose()
Workspace

14.
If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program?
#include<stdio.h>

int main()
{
    FILE *fs, *ft;
    char c[10];
    fs = fopen("source.txt", "r");
    c[0] = getc(fs);
    fseek(fs, 0, SEEK_END);
    fseek(fs, -3L, SEEK_CUR);
    fgets(c, 5, fs);
    puts(c);
    return 0;
}
A.
friend
B.
frien
C.
end
D.
Error in fseek();
Workspace

15.
According to ANSI specifications which is the correct way of declaring main when it receives command-line arguments?
A.
int main(int argc, char *argv[])
B.
int main(argc, argv)
int argc; char *argv;
C.
int main()
{
    int argc; char *argv;
}
D.
None of above
Workspace

16.
What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog one two three
/* myprog.c */
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char **argv)
{
    printf("%s\n", *++argv);
    return 0;
}
A.
myprog
B.
one
C.
two
D.
three
Workspace

17.
Point out the correct statement which correctly allocates memory dynamically for 2D array following program?
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *p, i, j;
    /* Add statement here */
    for(i=0; i<3; i++)
    {
        for(j=0; j<4; j++)
        {
            p[i*4+j] = i;
            printf("%d", p[i*4+j]);
        }
    }
    return 0;
}
A.
p = (int*) malloc(3, 4);
B.
p = (int*) malloc(3*sizeof(int));
C.
p = malloc(3*4*sizeof(int));
D.
p = (int*) malloc(3*4*sizeof(int));
Workspace

18.
malloc() allocates memory from the heap and not from the stack.
A.
True
B.
False
Workspace

19.
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
void display(char *s, ...);
int fun1();
int fun2();

int main()
{
    int (*p1)();
    int (*p2)();
    p1 = fun1;
    p2 = fun2;
    display("IndiaBIX", p1, p2);
    return 0;
}
void display(char *s, ...)
{
    int (*pp1)();
    int (*pp2)();
    va_list ptr;

    va_start(ptr, s);
    pp1 = va_arg(ptr, int(*)());
    (*pp1)();

    pp2 = va_arg(ptr, int(*)());
    (*pp2)();

}
int fun1()
{
    printf("Hello");
}
int fun2()
{
    printf("Hi");
}
A.
Error: invalid function display() call
B.
Error: invalid va_start(ptr, s);
C.
Error: va_arg cannot extract function pointer from variable argument list.
D.
Error: Rvalue required for t
Workspace

20.
What do the following declaration signify?
int (*ptr)[30];
A.
ptr is a pointer to an array of 30 integer pointers.
B.
ptr is a array of 30 integer function pointer.
C.
ptr is a array of 30 integer pointers.
D.
ptr is a array 30 pointers.

 Provide your Output in Comments. We will publish the output soon.

Comments

Popular posts from this blog

Tips 01) self introduction in an interview

Computer Science Terminology

Why Failure Is Good for Success