Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cybrscot

macrumors 6502
Original poster
Dec 7, 2010
282
0
Somewhere in Southeast Asia
***Damn, update**** I figured it out. I needed to declare the int values separately. I don't know why I couldn't do it like I did below, but declaring them separately worked. Sorry!!!!!


Hello! After taking the weekend off, due to work, sick, and needing to recharge the batteries after 4 straight chapters of learning to program, it's time to get going again. Anyway, my book asked me to show the output produced by each of the following code fragments, assume that i, j, and k are into variables.

Did I do something wrong? Or do I need to enable nested functions? I've seen the nested functions error before, but it was because I made an error in my code, not because I needed to use nested functions.

answer to below question is 63 8 By the way, I can do this in my head, but my compiler cannot!!

Question 1:
i = 7; j = 8;
i *= j +1 ;
printf ("%d %d", i, j) ;


My code as follows, typed exactly as in the book....

Code:
#include <stdio.h>

main ()
{
	int i = 7 ;
	int j = 8 ;
	int i *= j + 1 ;
	
	printf ("%d %d", i, j) ;
	
	return 0 ;
	
}


Output

Users/scottdean/documents/fragment.c: In function ‘main’:
/Users/scottdean/documents/fragment.c:7: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/scottdean/documents/fragment.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*=’ token
/Users/scottdean/documents/fragment.c:7: error: expected expression before ‘*=’ token
 
Last edited:
Thanks, oh I see, I declared the third line, which declared i again, makes sense now. Mind a bit rusty after two days off. This stuff keeps you sharp, well at least learning it from a book does!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.