porg question

C

chump1708

main()
{
int i;
clrscr();
printf("%d", &i)+1;
scanf("%d", i)-1;
}

whats the output n why???
Note that there is & which means it probably prints the address of
i...n my guess is that + 1 has no effect on the output...
n regarding scanf - there is no & symbol...so still it will accept a
value but not store it in i n my guess is that -1 has no effect on the
code....
any comments....
 
R

Robert Gamble


int main (void)
{
int i;
clrscr();

Not a standard function.
printf("%d", &i)+1;

printf is expecting an int, you are passing a pointer to int, this is
undefined behavior. Try printf("%d\n", i);
You need to #include <stdio.h> before calling printf.
You need to initialize i before using it's value, what you are doing is
undefined behavior.
scanf("%d", i)-1;

scanf is expecting a pointer to int, you are passing an int. Try
scanf("%d", &i);
You need to #include said:
}

whats the output n why???

You have several examples of undefined behavior in your program, this
means anything goes, you shouldn't expect anything in particular.
Note that there is & which means it probably prints the address of
i...n my guess is that + 1 has no effect on the output...

If you want to print the address, cast the address of i to a pointer to
void and use the %p conversion specifier:

printf("%p\n", (void *)&i);

printf returns an integer value. In your statement 1 is added to the
this value and the result is discarded. The compiler could legally
just remove the +1 as an optimization since your program wouldn't know
the difference, it doesn't use the result in any way.

Robert Gamble
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top