Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 45

Find the Output and Debugging

C Programming
1. Find the Output
struct
{
int si;
double d;
float cp;
} s;
void
main ()
{
printf ("%d, %d, %d", sizeof (s.si), sizeof (s.d), sizeof (s.cp));
}
Options:
a) 6, 10, 8
b) 4, 8, 4
c) 2, 4, 4
d) 2, 8, 8
2. Find the Output

int main ()
{
int a, b;
a = b = 4;
b = a++;
printf ("%d %d %d %d", a++, --b, ++a, b--);
}

Options:

A.5 3 7 3
B.5 4 5 3
C.6 2 6 4
D.Syntax Error
3. Find the Output

int main ()

int a[4] = { 25, 16 };

printf ("%d %d", a[0] & a[1], a[1] | a[2]);

Options:
a) Syntax error because of invalid operator symbol
b) 25 16
c) 16 16
d) Syntax error because of invalid array initialization
4 Find the Output
int main ()
{
static int num = 8;
printf ("%d", num = num - 2);
if (num != 0)
main ();
}
Options:

a) 8642
b) Infinite output
c) Invalid because main function can't call itself.
d) 6420
5.Find the Output
How many times “VIT Chennai" will print.
int main()
{
int x;
Options:
for(x=-1; x<=10; x++)
{ a) Infinite Time
b) 11 Times
if(x < 5)
c) 0 Time
continue; d) 10 Times
else
break;
printf(“VIT Chennai");
}
return 0;
}
6. Find the Output

int main()
{
int a = 10, b = 25;
a = b++ + a++;
b = ++b + ++a;
printf("%d %d n", a, b);
}

Options:
a) 36 64
b) 35 62
c) 36 63
d) 30 28
7. Find the Output

int main()

char arr[3]="Network";

printf("%s %s", arr,arr[3]);

return 0;

Options:
a) Network w
b) Nw
c) Net Garbage value
d) Compilation error
8. Find the Output

int main()

int x = 7538;

printf("%d %dn", x % 100, x / 10);

Options:

a) 38 753
b) 75 538
c) 538 38
d) 0 753
9. Find the Output

void fn()
{
static int i = 10;
printf("%d ", ++i);
}
int main()
{
fn();
fn();
}

Options:

a) 10 10
b) 11 11
c) 11 12
d) 12 12
10. Find the Output

int main ()

int x = 24, y = 39, z = 45; Options:


a) 24 39 63
z = x + y; b) 39 24 63
c) 24 39 45
y = z - y; d) 39 24 45
x = z - y;

printf ("%d %d %d", x, y, z);

}
11. Find the Output
int main ()
{
int check = 2;
switch (check)
{
case 1:
printf ("D.W.Steyn");
case 2:
printf (" M.G.Johnson");
case 3:
printf (" Mohammad Asif");
default:
printf (" M.Muralidaran");
} Options:
return 0; a) D.W.Steyn
} b) D.W.Steyn M.G.Johnson
c) M.G.Johnson
d) M.G.Johnson Mohammad Asif M.Muralidaran
12. Find the Output
int main ()
{
int a = 5;
float b;
printf ("%d", sizeof (++a + b));
printf (" %d", a);
return 0;
}

Options:

a) 65
b) 56
c) 45
d) 54
13. Find the Output

int main() {
int m = -10, n = 20;
n = (m < 0) ? 0 : 1;
printf("%d %d", m, n);
}

Options:

a) -10 0
b) 10 20
c) 20 -10
d) 01
14. Find the Output

int main() {
int i=0;
for(;;)
printf("%d",i);
return 0;
}

Options:
a) 0 times
b) Infinite times
c) 10 times
d) 1 times
15. Find the Output
int main() {

char c = 'f';

switch (c) {

default: printf("unknown colour ");

case 'r': case 'R': printf("Red ");

case 'g': case 'G': printf("Green "); break;

case 'b': case 'B': printf("Blue");

} }
Options:
a) unknown colour Red Green Blue
b) Error
c) Green unknown colour Red
d) unknown colour Red Green
16. Find the Output

int main() {
int k=40, *a;
(*a)++; k++;
printf("n k=%d",k);
}

Options:

a) k=40
b) k=44
c) k=42
d) k=40
17. Find the Output
int main() {

int x = 1;

while(x=0)

printf("hello");

printf("While didn't run");


}

Options:
a) hello
b) No output
c) Infinite time hello display
d) While didn’t run
18. Find the Output
int main() {
int x = 0, y = 0;
if(x > 0)
if(y > 0)
printf("True");
else
printf("False");
}
Options:
a) No Output
b) True
c) False
d) Error because of dangling else problem
19. Find the Output

main() {

int i = 2, *j;

j = &i;

printf("%d", i**j*i+*j);

Options:
a) Syntax error due to Invalid expression in
printf
b) Print junk value
c) 16
d) 10
20. Find the Output
int main()
Options:
{
a) Nagpur
char str[] = "Nagpur"; b) Kanpur
c) Kagpur
str[0]='K';
d) anpur
printf("%s, ", str); e) Error

str = "Kanpur";
printf("%s", str+1);
return 0; }
21. Find the Output

int main() Options:

{ a) The sentence will get printed in same order as it entered


b) The sentence will get printed in reverse order
char sentence[80]; c) The sentence will get half printed
d) Error
int i;
printf("Enter a line of text\n");
gets(sentence);
for(i=strlen(sentence)-1; i >=0; i--)
putchar(sentence[i]);
return 0;
}
22. Find the Output
int main()
{
char t;
char *p1 = "India", *p2;
p2=p1;
p1 = "BIX";
printf("%s %s\n", p1, p2);
return 0;
}

Options:
a) India BIX
b) BIX India
c) India BIX
d) BIX BIX
23. Find the Output

int main()
Options:
{ a) The string is not empty
int i; b) The string is empty
c) Error
char a[] = "\0";
if(printf("%s", a))
printf("The string is not empty\n");
else
printf("The string is empty\n");
return 0;
}
24. Find the Output

void main()

int a[3] = {1, 2, 3};

int *p = a;

printf("%p\t%p", p, a);

}
25. Find the Output
void main()

char *s= "hello";

char *p = s;

printf("%c\t%c", *(p + 3), s[1]);

}
26. Find the Output

int main()

int ary[4] = {1, 2, 3, 4};

int p[4];

p = ary;

printf("%d\n", p[1]);

}
27. Find the Output
void func();

int main()

static int b = 20;

func();

void func()

static int b;

printf("%d", b);

}
28. Find the Output
struct p
{
int k;

char c;

float f;
};

int p = 10;

int main()

{
struct p x = {1, 97};

printf("%f %d\n", x.f, p);

}
29. Find the Output

int main()
{
static int var[5];
int count=0;

var[++count]=++count;
for(count=0;count<5;count++)
printf("%d ",var[count]);

return 0;
}
30. Find the Output

struct sample
{
int a=0;
char b='A';
float c=10.5;
};
int main()
{
struct sample s;
printf("%d,%c,%f",s.a,s.b,s.c);
return 0;
}
31. Find the Output
struct student
{
char name[20];
}std;
char * fun(struct student *tempStd)
{
strcpy(tempStd->name,"Thomas");
return tempStd->name;
}

int main()
{
strcpy(std.name,"Mike ");
printf("%s%s",std.name,fun(&std));
return 0;
}
32. Find the Output

int main()
{
typedef struct tag{
char str[10];
int a;
}har;

har h1,h2={"IHelp",10};
h1=h2;
h1.str[1]='h';
printf("%s,%d",h1.str,h1.a);
return 0;
}
33. Find the Output

int main()
{
typedef int AAA,BBB,CCC,DDD;
AAA aaa=10;
BBB bbb=20;
CCC ccc=30;
DDD ddd=40;
printf("%d,%d,%d,%d",aaa,bbb,ccc,ddd);
return 0;
}
34. Find the Output

int main()
{
int var=100;
{
int var=200;
printf("%d...",var);
}
printf("%d",var);
return 0;
}
1. Debug the code segment

int main()
{
int x[10]={0,1,2,3,4,5,6,7,8,9};
int *ptr1,*ptr2;
ptr1=&x[0];
ptr2=&x[5];

printf("%p\n",(ptr1+ptr2));

return 0;
}
2. Debug the code segment
#include
int main()
{
float x = 1.1;
switch (x)
{
case 1: printf("Choice is 1");
break;
default: printf("Invalid choice");
break;
}
return 0;
}
3. Debug the code segment
Check whether the below program print the
below pattern
#include <stdio.h>
int main() Input
{ enter number of rows : 4
int i,j,n; Output
printf("Enter the number of rows: "); 1
scanf("%d",&n); 22
for(i=1;i<=n;i=i+1) 333
{ 4444
for(j=1;j<=i;j=j+1) 4444
{ 333
printf("%d",i); 22
} 1
printf("\n");
}
for(i=n;i>=1;i=i-1)
{
for(j=1;j<=i;j=j-1)
{
printf("%d",i);
}}
4. Debug the code segment
Question
You have to find the security key from the data transmitted.
Input
The input consists of an integer data, representing the data to be
transmitted.
Output
Print an integer representing the security key for the given data.
Example
Input
578378923
Output
783
Explanation
The repeated digits in the data are 7, 8 and 3. So, the security key is
783
#include <stdio.h>
int main()
{
char a[50];
int i, j, len, count;

scanf("%c",a);
strlen(a);

for(i=0;i<len;i++)
{
for(j=i+1;j<len;j++)
{
if(a[i]=a[j])
{
printf("%c",a[i]);
break;
}}}
1. Given an array of size N check whether the given array
is a ‘Palindromic Array’ or not. If not a Palindromic array
then convert the array in to Palindromic array.

Input array:
53333
Output:
Not a Palindromic Array
33533

Input array:
5335
Output:
Palindromic array!!
2. Run-length encoding is one of the compression
techniques commonly used. The encoding is done
by finding the frequency of each letters in a string.
Say for example if the enter string
‘aaaabbcccccddf’ then the encoded string is :
4a2b5c2d1f.
3. Write a function pattern ( ) to find the number of pattern {1 0 1}
from the given input binary sequence string.

Input:
001010100001101
Output:
3
Input:
111111111111111111111110
Output:
0
4. Write a function pattern ( ) to find the number of pattern {1 0 1}
from the given input binary sequence string.

Input:
1 2 3 4
6 7 8 9
10 11 12 13
14 15 16 17

Output:
1 2 3 4 9 13 17 16 15 14 10 6 7 8 12 11
5. A Pythagorean triplet is a set of three integers a, b and c

such that a2 + b2 = c2. Given a limit, generate all

Pythagorean Triplets with values smaller than given limit.

Input :
limit = 20

Output :
345
8 6 10
5 12 13
15 8 17
12 16 20

You might also like