Programing Questions - A virus
test banner

Post Top Ad

Responsive Ads Here

Programing Questions

Share This

IBM Coding Questions with Answers 2021 (Updated)
Most aksed IBM Coding Questions with Solutions are here. Most Recent IBM Programming & Coding Questions 2021 with Solution

TCS, Accenture, infosys, Wipro, IBM Programing Questions

#Programing



Q1: What is the output of this C code?

#include <stdio.h>

int main(){

int i = 10;

int *p = &i;

printf("%d\n",*p++);

}


Output: 10


Q2: What is the output of this C code?

#include <stdio.h>

void main()

{

    int x=4;

    int *p=&x;

    int *k=p++;

    int r=p-k;

    printf("%d",r);

}


output: 1


Q3: What is the output of this C code?

#include <stdio.h>

void reverse(int i);

int main()

{

    reverse(1);

}

void reverse(int i)

{

    if(i>5)

        return;

    printf("%d",i);

    return reverse((i++,i));

}


Output : 12345


Q4: What is the output of this C++ code?

#include<iostream>

using namespace std;

void copy(int& a, int& b, int& c)

{

    a*=2;

    b*=2;

    c*=2;

}

int main()

{

    int x=1, y=3, z=7;

    copy(x,y,z);

    cout<<"x="<<x<<",y="<<y<<",z="<<z;

    return 0;

}

output: x=2,y=6,z=14


Q5: What is the output of this C++ code?

#include <iostream>

using namespace std;

int main()

{

    int a=5, b=6; c, d;

    c=a,b;

    b=(a,b);

    cout<<c<<"<<d;

    return 0;

}

output: Use of undeclared identifier ‘c' and Expected expression

Q6: What is the output of this C code?

#include <stdio.h>

#include <string.h>

int main()

{

    char *str="x";

    char c='x';

    char ary[1];

    ary[0]=c;

    printf("%d %d", strlen(str),strlen(ary));

    return 0;

}


output: 1 4 or 1 (undefined value)


Q7: What is the output of this C code?

#include <stdio.h>

int main()

{

    int x=0;

    if(x==0)

        printf("true,");

    else if (x= 10)

        printf("false,");

    printf("%d\n",x);

}

output: true,0


Q8: What is the output of this C++ code?

using namespace std;

int main()

{

    int x, y;

    x=5;

    y=++x* ++x;

    cout<<x<<y;

    x=5;

    y=x++* ++y;

    cout<<x<<y;

    return 0;

}

output :Multiple unsequenced modifications to ‘x' or Use of undeclared identifier ‘cout'


Q9: What is the output of this C++ code?

#include <iostream>

using namespace std;

void print(int i)

{

    cout<<i;

}

void print(double t)

{

    cout<<t;

}

int main(void)

{

    print(5);

    print(500.263);

    return 0;

}

output: 5500.263


Q9: What is the output of this C code?

#include <stdio.h>

#define MAX 2

enum bird {SPARROW =MAX+1, PARROT=SPARROW+MAX};

int main()

{

    enum bird b=PARROT;

    printf("%d\n",b);

    return 0;

}

output: 5 


Q10: What is the output of this C++ code?

#include <iostream>

    using namespace std;

    struct sec {

        int a;

        char b;

    };

    int main()

    {

        struct sec s ={25,50};

        struct sec *ps =(struct sec *)&s;

        cout << ps->a << ps->b;

        return 0;

    }

output: 252

Explanation :

In this program, We are dividing the values of a and b, printing it.
Output:
$ g++ stu5.cpp
$ a.out
252


Q11: What is the output of this C code?

#include <stdio.h>

void main()

{

    static int x;

    if (x++<2)

        main();

}

output: Main is called twice


Q12: What is the output of this C code?

void main ()

{

    long myarr[2][4]={0|,2|,3|,4|,5|,6|,7|};

    printf("%|d\t",myarr[1][2]);

    printf("%|d%|d\t",*(myarr[1]+3),3[myarr[1]]);

    printf("%|d%|d%|d\t",*(*(myarr+1)+2),*(1[myarr]+2),3[1[myarry]]);

}


Output: Compilation error


Q12: What would be the output of the following?

#include <iostream.h>

void main()

{

    char *ptr="abcd"

    char ch;

    ch=++*ptr++;

    cout<<ch;

}

output: b

Q13: comment on the output of the c code?

#include <stdio.h>

struct temp

{

    int a;

    int b;

    int c;

};

main()

{

    struct temp p[]={{1,2,3},{4,5,6},{7,8,9};

}


Answer: No Compile time error, generates an array of structure of size 3


Q14:  what will be the output when following code is executed.

int a =10, b;

b=a++ + ++a;

printf(“%d,%d,%d,%d",b,a++,a,++a);


Answer: 22,13,14,14 or 22,13,13,13


Q15: what is the output of the following program?

#include <stdio.h>

static int i;

static int i= 10;

static int j;

int main()

{

    static int i;

    printf("%d",i);

    return 0;

}

output: 0


Q15: what is the output of this c code?

#include <stdio.h>

void main()

{

    int x=1,y=0, z=5;

    int a=x&& y||z++;

    printf("%d",z);

}


output: 6


Q16: what is the output of this c code?

#include <iostream>

using namespace std;

int main()

{

    int a=5, b=6,c;

    c=(a>b)?a:b;

    cout<<c;

    return 0;

}


output: 6


Q17: what is the output of this c code?

#include <iostream>

using namespace std;

int main()

{

    char arr[20];

    int i;

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

    *(arr +i)=65+i;

    *(arr+i)='\10';

    cout<<arr;

    return 0;

}

output:ABCDEFGHIJ


Q18: what is the output of this  code?

#include <iostream>

using namespace std;

void fun(int x, int y)

{

    x=20;

    y=10;

}

int main()

{

    int x=10;

    fun(x,x);

    cout<<x;

    return 0;

}

output: 10


Q19: what is the output of this c code?

#include <stdio.h>

int main()

{

    int a=2;

    int b=0;

    int y=(b==0)?a:(a>b)?(b=1):a;

    printf("%d\n",y);

}

output: 2


Q20: what is the output of this c code?

#include<stdio.h>

void f(int *p, int *q)

{

p = q;

*p = 2;

}

int i = 0, j = 1;

int main()

{

f(&i, &j);

printf("%d %d \n", i, j);

getchar();

return 0;

}

output: 0 2

Q21: what is the output of this c code?

#include<stdio.h>

int main()

{

    int var=010;

    printf("%d",var);

}

output: 8




1 comment:

  1. As an oncologist, he has performed procedures such as breast and gynaecologic, gastrointestinal, Head & neck, Thoracic, Urological and musculoskeletal oncology.

    ReplyDelete

Post Bottom Ad

Responsive Ads Here

Pages