English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

main()
{
int i=9;
clrscr();
printf("%d\n", &i)+1;//why this code has no effect
scanf("%d", i)-1;
}//after compilation no problem butwhen u see the out put by pressing alt+f5
it is giving null pionter assignment

2007-09-09 18:25:44 · 1 answers · asked by karan c 1 in Computers & Internet Programming & Design

1 answers

Hi,
In printf statement u have added 1. Since printf() returns some integer value, u add 1 to that integer value this becomes like incomplete numeric expression. See the difference a=b+c or b+c. ur printf is like expression b+c where two integers are added but the result is not saved in any variable. Suppose printf() returns 2 then ur stetement becomes 2+1; (like b+c). Therefore it does not have any effect. Instead u write j=printf("%d\n",&i)+1; or u write
printf("%d",printf("%d\n",&i)+1);
This is like printf("%d",b+c);
Similary explanation follows for scanf() also as scanf() also return an integer value.

2007-09-09 21:39:56 · answer #1 · answered by iqbal 4 · 0 0

fedest.com, questions and answers