why this small code is not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

why this small code is not working?

i have to options: 1- use a counter c and use it in ( b for loop). 2- use a counter sum and then pass it in two for loops ( in this code). i have tried the 2 ways and i get bad results. https://code.sololearn.com/cKIuSU9SRtCJ/?ref=app

9th Jan 2019, 6:06 AM
Ahmad Ali
Ahmad Ali - avatar
3 Answers
+ 7
First of all, you have used the concept of dynamic initialization i.e. you have directly declared the i and j variables in for loop which is not supported in C as C is procedure oriented language. Declare i and j along with a and b. Then remove the int from both i and j. Then see, the program will run. But I don't understand, exactly what your program is doing ?? Why have you used a pointer sum ??
9th Jan 2019, 8:26 AM
Nova - avatar
+ 4
Part A 1. Initialize pointer sum as pointing to NULL. 2. Declare a variable as location of the pointer. 3. Assign your pointer to point to the LOCATION of the variable. 4. Update the pointed variable by using parathese (*sum) 5. Print *sum not sum 6. %d not %i B. Fixed for your reference https://code.sololearn.com/cK2bfJ2SNRX6/?ref=app C. You need to play with these example codes about pointer. https://www.sololearn.com/learn/C/2933/
9th Jan 2019, 8:36 AM
Gordon - avatar
+ 4
In the 8th line you've written sum instead of *sum
8th Feb 2019, 4:24 PM
Gujjula Pradeep Reddy
Gujjula Pradeep Reddy - avatar