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

No comments: