The compiler i use is LCC-WIN 32
This is how i have written the program and the warnings.
1 #include<stdio.h>
2 void afunction(int *x)
3 {
4 x=new int;
5 *x=12;
6 }
7 int main()
8 {
9 int v=10;
10 afunction(&v);
11 printf("%d",v);
12 }
Error c:\lcc\test.c: 4 undeclared identifier 'new'
Error c:\lcc\test.c: 4 operands of = have illegal types 'pointer to int' and 'int'
Warning c:\lcc\test.c: 4 possible usage of new before definition
Error c:\lcc\test.c: 4 Syntax error; missing semicolon before `int'
Error c:\lcc\test.c: 4 empty declaration
Compilation + link time:0.7 sec, Return code: 1
As for the other questions i haven't yet understand the following:
#10 why does the loop stop when i=0?
#17 i don't understand why the precedence affects the value of b
Thanks
|
Light Poster
|
|
| 2Aug2007,17:24 | #11 |
|
Go4Expert Founder
|
![]() |
| 2Aug2007,20:43 | #12 |
|
I am not sure about the error but I can explain about the other 2.
When anything becomes zero its equal to false or else its true. In C there is nothing bool but everything is with respect to 0 and Non zero. 0 being false and Non Zero is true. Say if you have something like if(1) will always be true. Regarding precedence try expanding the macro on pen and paper and you will see both evaluation does not come out to be same. |
|
Light Poster
|
|
| 2Aug2007,21:38 | #13 |
|
Quote:
Originally Posted by shabbir |
|
Go4Expert Founder
|
![]() |
| 3Aug2007,08:12 | #14 |
|
I should become -1 in ++i for the expression to become 0 and if it becomes 0 then ++i becomes 1 and the same logic goes for i++ but its the increment that is done after the loop breaking condition check.
|
|
Light Poster
|
|
| 3Aug2007,10:24 | #15 |
|
Code:
1 #include<stdio.h>
2 void afunction(int *x)
3 {
4 x=new int;
5 *x=12;
6 }
7 int main()
8 {
9 int v=10;
10 afunction(&v);
11 printf("%d",v);
12 }
Error c:\lcc\test.c: 4 undeclared identifier 'new'
Error c:\lcc\test.c: 4 operands of = have illegal types 'pointer to int' and 'int'
Warning c:\lcc\test.c: 4 possible usage of new before definition
Error c:\lcc\test.c: 4 Syntax error; missing semicolon before `int'
Error c:\lcc\test.c: 4 empty declaration
Compilation + link time:0.7 sec, Return code: 1
|
|
Go4Expert Member
|
![]() |
| 3Aug2007,13:36 | #16 |
|
Try this coding in the manner...........u got answer
Code:
#include <stdio.h>
void afunction(int *x)
{
x=new int;
*x=12;
}
int main()
{
int v=10;
afunction(&v);
printf("%d",v);
return 0;
}
Last edited by shabbir; 4Aug2007 at 12:09.. Reason: Code block - http://www.go4expert.com/forums/misc.php?do=bbcode#code |
|
Light Poster
|
|
| 3Aug2007,15:57 | #17 |
|
Quote:
Originally Posted by seeguna
|
|
Go4Expert Member
|
![]() |
| 4Aug2007,09:33 | #18 |
|
Run it in Microsoft Vc++ compiler ...
U will get an answer of value "10" |
|
Light Poster
|
|
| 4Aug2007,10:45 | #19 |
|
thanks
|
|
Go4Expert Founder
|
![]() |
| 4Aug2007,12:45 | #20 |
|
Quote:
Originally Posted by psapikas |


