Thursday, July 31, 2014

C Programming

1. 
What will be the output of the program?
#include<stdio.h>
int fun(int(*)());

int main()
{
    fun(main);
    printf("Hi\n");
    return 0;
}
int fun(int (*p)())
{
    printf("Hello ");
    return 0;
}
A.Infinite loopB.Hi
C.Hello HiD.Error
2. 
What will be the output of the program?
#include<stdio.h>

int fun(int i)
{
    i++;
    return i;
}

int main()
{
    int fun(int);
    int i=3;
    fun(i=fun(fun(i)));
    printf("%d\n", i);
    return 0;
}
A.5B.4
C.ErrorD.Garbage value
3. 
What will be the output of the program?
#include<stdio.h>
int fun(int);
int main()
{
    float k=3;
    fun(k=fun(fun(k)));
    printf("%f\n", k);
    return 0;
}
int fun(int i)
{
    i++;
    return i;
}
A.5.000000B.3.000000
C.Garbage valueD.4.000000

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

int main()
{
    int i=0;
    i++;
    if(i<=5)
    {
        printf("IndiaBIX");
        exit(1);
        main();
    }
    return 0;
}
A.Prints "IndiaBIX" 5 times
B.Function main() doesn't calls itself
C.Infinite loop
D.Prints "IndiaBIx"
5. 
Which of the following statements are correct about the program?
#include<stdio.h>

int main()
{
    printf("%p\n", main());
    return 0;
}
A.It prints garbage values infinitely
B.Runs infinitely without printing anything
C.Error: main() cannot be called inside printf()
D.No Error and print nothing

Wednesday, July 30, 2014

C Programming

1. 
What will be the output of the program?
#include<stdio.h>
int i;
int fun1(int);
int fun2(int);

int main()
{
    extern int j;
    int i=3;
    fun1(i);
    printf("%d,", i);
    fun2(i);
    printf("%d", i);
    return 0;
}
int fun1(int j)
{
    printf("%d,", ++j);
    return 0;
}
int fun2(int i)
{
    printf("%d,", ++i);
    return 0;
}
int j=1;
A.3, 4, 4, 3B.4, 3, 4, 3
C.3, 3, 4, 4D.3, 4, 3, 4

2. 
What will be the output of the program?
#include<stdio.h>
int func1(int);

int main()
{
    int k=35;
    k = func1(k=func1(k=func1(k)));
    printf("k=%d\n", k);
    return 0;
}
int func1(int k)
{
    k++;
    return k;
}
A.k=35B.k=36
C.k=37D.k=38

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

int addmult(int ii, int jj)
{
    int kk, ll;
    kk = ii + jj;
    ll = ii * jj;
    return (kk, ll);
}

int main()
{
    int i=3, j=4, k, l;
    k = addmult(i, j);
    l = addmult(i, j);
    printf("%d, %d\n", k, l);
    return 0;
}
A.12, 12B.7, 7
C.7, 12D.12, 7
4. 
What will be the output of the program?
#include<stdio.h>
int check(int);
int main()
{
    int i=45, c;
    c = check(i);
    printf("%d\n", c);
    return 0;
}
int check(int ch)
{
    if(ch >= 45)
        return 100;
    else
        return 10;
}
A.100B.10
C.1D.0
5. 
If int is 2 bytes wide.What will be the output of the program?
#include <stdio.h>
void fun(char**);

int main()
{
    char *argv[] = {"ab", "cd", "ef", "gh"};
    fun(argv);
    return 0;
}
void fun(char **p)
{
    char *t;
    t = (p+= sizeof(int))[-1];
    printf("%s\n", t);
}
A.abB.cd
C.efD.gh

Tuesday, July 29, 2014

C Programming

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

int main()
{
    int fun(int);
    int i = fun(10);
    printf("%d\n", --i);
    return 0;
}
int fun(int i)
{
   return (i++);
}
A.9B.10
C.11D.8
2. 
What will be the output of the program?
#include<stdio.h>
int check (int, int);

int main()
{
    int c;
    c = check(10, 20);
    printf("c=%d\n", c);
    return 0;
}
int check(int i, int j)
{
    int *p, *q;
    p=&i;
    q=&j;
    i>=45 ? return(*p): return(*q);
}
A.Print 10B.Print 20
C.Print 1D.Compile error
3. 
What will be the output of the program?
#include<stdio.h>
int fun(int, int);
typedef int (*pf) (int, int);
int proc(pf, int, int);

int main()
{
    printf("%d\n", proc(fun, 6, 6));
    return 0;
}
int fun(int a, int b)
{
   return (a==b);
}
int proc(pf p, int a, int b)
{
   return ((*p)(a, b));
}
A.6B.1
C.0D.-1
4. 
What will be the output of the program?
#include<stdio.h>

int main()
{
    int i=1;
    if(!i)
        printf("IndiaBIX,");
    else
    {
        i=0;
        printf("C-Program");
        main();
    }
    return 0;
}
A.prints "IndiaBIX, C-Program" infinitely
B.prints "C-Program" infinetly
C.prints "C-Program, IndiaBIX" infinitely
D.Error: main() should not inside else statement
5. 
What will be the output of the program?
#include<stdio.h>

int addmult(int ii, int jj)
{
    int kk, ll;
    kk = ii + jj;
    ll = ii * jj;
    return (kk, ll);
}

int main()
{
    int i=3, j=4, k, l;
    k = addmult(i, j);
    l = addmult(i, j);
    printf("%d %d\n", k, l);
    return 0;
}
A.12 12
B.No error, No output
C.Error: Compile error
D.None of above

Monday, July 28, 2014

C Programming

1. 
The keyword used to transfer control from a function back to the calling function is
A.switchB.goto
C.go backD.return
2. 
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
3. 
How many times the program will print "IndiaBIX" ?
#include<stdio.h>

int main()
{
    printf("IndiaBIX");
    main();
    return 0;
}
A.Infinite timesB.32767 times
C.65535 timesD.Till stack overflows
4. 
What will be the output of the program in 16 bit platform (Turbo C under DOS)?
#include<stdio.h>

int main()
{
    int fun();
    int i;
    i = fun();
    printf("%d\n", i);
    return 0;
}
int fun()
{
    _AX = 1990;
}
A.Garbage valueB.0 (Zero)
C.1990D.No output
5. 
What will be the output of the program?
#include<stdio.h>
void fun(int*, int*);
int main()
{
    int i=5, j=2;
    fun(&i, &j);
    printf("%d, %d", i, j);
    return 0;
}
void fun(int *i, int *j)
{
    *i = *i**i;
    *j = *j**j;
}
A.5, 2B.10, 4
C.2, 5D.25, 4
6.
What will be the output of the program?
#include<stdio.h>
int i;
int fun();

int main()
{
    while(i)
    {
        fun();
        main();
    }
    printf("Hello\n");
    return 0;
}
int fun()
{
    printf("Hi");
}
A.HelloB.Hi Hello
C.No outputD.Infinite loop
7. 
What will be the output of the program?
#include<stdio.h>
int reverse(int);

int main()
{
    int no=5;
    reverse(no);
    return 0;
}
int reverse(int no)
{
    if(no == 0)
        return 0;
    else
        printf("%d,", no);
    reverse (no--);
}
A.Print 5, 4, 3, 2, 1B.Print 1, 2, 3, 4, 5
C.Print 5, 4, 3, 2, 1, 0D.Infinite loop
.
8. 
What will be the output of the program?
#include<stdio.h>
void fun(int);
typedef int (*pf) (int, int);
int proc(pf, int, int);

int main()
{
    int a=3;
    fun(a);
    return 0;
}
void fun(int n)
{
    if(n > 0)
    {
        fun(--n);
        printf("%d,", n);
        fun(--n);
    }
}
A.0, 2, 1, 0,B.1, 1, 2, 0,
C.0, 1, 0, 2,D.0, 1, 2, 0,
9. 
What will be the output of the program?
#include<stdio.h>
int sumdig(int);
int main()
{
    int a, b;
    a = sumdig(123);
    b = sumdig(123);
    printf("%d, %d\n", a, b);
    return 0;
}
int sumdig(int n)
{
    int s, d;
    if(n!=0)
    {
        d = n%10;
        n = n/10;
        s = d+sumdig(n);
    }
    else
        return 0;
    return s;
}
A.4, 4B.3, 3
C.6, 6D.12, 12
 10.
What will be the output of the program?
#include<stdio.h>

int main()
{
    void fun(char*);
    char a[100];
    a[0] = 'A'; a[1] = 'B';
    a[2] = 'C'; a[3] = 'D';
    fun(&a[0]);
    return 0;
}
void fun(char *a)
{
    a++;
    printf("%c", *a);
    a++;
    printf("%c", *a);
}
A.ABB.BC
C.CDD.No output