My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
Advertisements
|
C Debugging - Part 7
Posted Date: 05 May 2008 Resource Type: Articles/Knowledge Sharing Category: Placement Papers
|
Posted By: Ramkumar Member Level: Diamond Rating: Points: 3
|
|
|
|
Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Ø Programs run under DOS environment,
Ø The underlying machine is an x86 system,
Ø Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:
71) #include
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}
Answer:
Compiler error
Explanation:
i is a constant. you cannot change the value of constant
72) #include
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d.. %d",*p,*q) ;
}
Answer:
garbagevalue. .1
Explanation:
p=&a[2][2][2] you declare only two 2D arrays. but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. now q is pointing to starting address of a.if you print *q meAnswer:it will print first element of 3D array.
73) #include
main()
{
register i=5;
char j[]= "hello";
printf("%s %d",j,i);
}
Answer:
hello 5
Explanation:
if you declare i as register compiler will treat it as ordinary integer and it will take integer value. i value may be stored either in register or in memory.
74) main()
{
int i=5,j=6,z;
printf("%d", i+++j);
}
Answer:
11
Explanation:
the expression i+++j is treated as (i++ + j)
76) struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi, jkl;
int x=100;
abc.i=0;abc. prev=&jkl;
abc.next=&def;
def.i=1;def. prev=&abc;def.next=&ghi;
ghi.i=2;ghi. prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl. prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d", x);
}
Answer:
2
Explanation:
above all statements form a double circular linked list;
abc.next->next->prev->next->i
this one points to "ghi" node the value of at particular node is 2.
77) struct point
{
int x;
int y;
};
struct point origin,*pp;
main()
{
pp=&origin;
printf("origin is(%d%d)\n", (*pp).x,( *pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
Answer:
origin is(0,0)
origin is(0,0)
Explanation:
pp is a pointer to structure. we can access the elements of the structure either with arrow mark or with indirection operator.
Note:
Since structure point is globally declared x & y are initialized as zeroes
78) main()
{
int i=_l_abc(10) ;
printf("%d\n" ,--i);
}
int _l_abc(int i)
{
return(i++);
}
Answer:
9
Explanation:
return(i++) it will first return i and then increments. i.e. 10 will be returned.
79) main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p.. .%p...%p" ,p,q,r);
}
Answer:
0001...0002. ..0004
Explanation:
++ operator when applied to pointers increments address according to their corresponding data-types.
80) main()
{
char c=' ',x,convert( z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c) ;
printf("%c", x);
}
convert(z)
{
return z-32;
}
Answer:
Compiler error
Explanation:
declaration of convert and format of getc() are wrong.
Regards, Ram...
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|
|