Créer un compte gratuit
Rejoignez Calaméo pour publier et partager vos documents !
Notez et commentez vos publications favorites, téléchargez des documents, partagez vos lectures avec vos amis.
13-JoP-Jan-08
1 pages
Publié par
sgganesh
Copyright :
Tous droits réservés
www.
linuxforu.
com | LINUX FOR YOU | JANUARY 2008
C M Y K
127
1) This program had an assertion failure.
Why?
struct bitfield {
signed int b : 1;
} bit;
int main() {
bit.
b = 1;
assert(bit.
b == 1);
}
2) This function worked fine for...
[Plus]
www.
linuxforu.
com | LINUX FOR YOU | JANUARY 2008
C M Y K
127
1) This program had an assertion failure.
Why?
struct bitfield {
signed int b : 1;
} bit;
int main() {
bit.
b = 1;
assert(bit.
b == 1);
}
2) This function worked fine for many years and
suddenly, for some value of i, the assertion failed.
What was
that value of i for which it failed and why?
int my_abs(int i) {
if (i < 0) {
i = -i;
}
assert(i >= 0);
return i;
}
3) The following function was written with an intention
that the printf should never be executed.
But for some value
of d, the message got printed! What is that value of ‘d’?
void oops(double d) {
if(d != d)
printf(“Oops! Something went wrong”);
}
4) The following program, when run, gave the output:
sqrt of 2=1557547102.
000000 instead of: sqrt of 2=1.
414214.
What could be the problem?
int main() {
double x = sqrt(2);
printf("sqrt of 2=%lf", x);
}
5) This program core-dumped at runtime instead of
printing “hi”; can you find out why?
int main() {
char * msg = ‘hi
[Moins]
Tags
assertion,
condition,
double,
function,
ganeshs,
int_min,
main,
number,
output,
printf,
program,
programming,
prototype,
size,
solution,
special,
sqrt