A
aarklon
Hi all,
I was going through the Book "The Hidden Treasure of C" by
Rajiv Dharaskar,First edition 1995, 2005 reprint,ISBN-81-7029-550-5
published in india by BPB publications
The following are my questions after going through the book
1)
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
int
main (void)
{
register int i;
volatile int j;
auto int k;
time_t s1, s2, s3, e1, e2, e3;
s1 = clock ();
for (i = 1; i <= 32000; i++)
e1 = clock ();
printf ("\n The time in seconds for register variable is %g\n",
difftime (e1, s1) / CLOCKS_PER_SEC);
s2 = clock ();
for (j = 1; j <= 32000; j++);
e2 = clock ();
printf ("\n The time in seconds for volatile variable is %g\n",
difftime (e2, s2) / CLOCKS_PER_SEC);
s3 = clock ();
for (j = 1; j <= 32000; j++);
e3 = clock ();
printf ("\n The time in seconds for auto variable is %g\n",
difftime (e3, s3) / CLOCKS_PER_SEC);
puts ("");
return (EXIT_SUCCESS);
}
I got the o/p as
The time in seconds for register variable is 0.02
The time in seconds for volatile variable is 0.01
The time in seconds for auto variable is 0
does this mean that accessing register variables is a slow
operation...???
2) why printf("\n ~5 = %d",~5); is giving o/p as -6
(how is 5 treated as an unsigned quantity or signed quantity)
or by default how does the compiler treats numeric literals..??
3) why a global declaration such as register int i; is not
allowed.
4) consider the following program
int
main (void)
{
int i;
printf("%d",sizeof i );
puts ("");
return (EXIT_SUCCESS);
}
it is giving the expected o/p 4 but when i change the line
printf("%d",sizeof i ); to printf("%d",sizeof int );
it is giving compilation error. why is this so..??
5) why the following declaration
extern static int i is not possible in C.
6) how correct is the usage of continue statement
instead of break statement in a switch.
I have heard that continue statement should be used only
within loops.
7) why the statement void aa=78; is not possible in C..??
8) i have seen a statement like printf("%Fp",main);
what exactly is the purpose of this format specifier %Fp
9) In this book an explanation is given as follows:-
if you try to write 'double' or 'float' type of variables in
hexadecimal or octal format, the compiler does not generate
any error message, but results obtained will be incorrect.
To what extent this explanation is true...????
I was going through the Book "The Hidden Treasure of C" by
Rajiv Dharaskar,First edition 1995, 2005 reprint,ISBN-81-7029-550-5
published in india by BPB publications
The following are my questions after going through the book
1)
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
int
main (void)
{
register int i;
volatile int j;
auto int k;
time_t s1, s2, s3, e1, e2, e3;
s1 = clock ();
for (i = 1; i <= 32000; i++)
e1 = clock ();
printf ("\n The time in seconds for register variable is %g\n",
difftime (e1, s1) / CLOCKS_PER_SEC);
s2 = clock ();
for (j = 1; j <= 32000; j++);
e2 = clock ();
printf ("\n The time in seconds for volatile variable is %g\n",
difftime (e2, s2) / CLOCKS_PER_SEC);
s3 = clock ();
for (j = 1; j <= 32000; j++);
e3 = clock ();
printf ("\n The time in seconds for auto variable is %g\n",
difftime (e3, s3) / CLOCKS_PER_SEC);
puts ("");
return (EXIT_SUCCESS);
}
I got the o/p as
The time in seconds for register variable is 0.02
The time in seconds for volatile variable is 0.01
The time in seconds for auto variable is 0
does this mean that accessing register variables is a slow
operation...???
2) why printf("\n ~5 = %d",~5); is giving o/p as -6
(how is 5 treated as an unsigned quantity or signed quantity)
or by default how does the compiler treats numeric literals..??
3) why a global declaration such as register int i; is not
allowed.
4) consider the following program
int
main (void)
{
int i;
printf("%d",sizeof i );
puts ("");
return (EXIT_SUCCESS);
}
it is giving the expected o/p 4 but when i change the line
printf("%d",sizeof i ); to printf("%d",sizeof int );
it is giving compilation error. why is this so..??
5) why the following declaration
extern static int i is not possible in C.
6) how correct is the usage of continue statement
instead of break statement in a switch.
I have heard that continue statement should be used only
within loops.
7) why the statement void aa=78; is not possible in C..??
8) i have seen a statement like printf("%Fp",main);
what exactly is the purpose of this format specifier %Fp
9) In this book an explanation is given as follows:-
if you try to write 'double' or 'float' type of variables in
hexadecimal or octal format, the compiler does not generate
any error message, but results obtained will be incorrect.
To what extent this explanation is true...????