Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very very basic query on programming in C -- displaying int value

Tags:

c

int

When I compile this little program instead of displaying "num1:7 , num2: 2", it displays "num1:-1218690218 , num2:-1217453276". I think I'm not specifying what the program should display so its just giving me the int range instead. I'm sorry.

#include <stdio.h>
main() {
     int num1 = 7, num2 = 2;                
     printf("num1:%d , num2:%d\n"), num1, num2;
}

EDIT: Thank you so much! The purpose of the exercise was to correct syntax errors, but whenever I compiled it I never got any warnings. That parenthesis is so easy to miss.

like image 863
jrasa Avatar asked Nov 27 '22 14:11

jrasa


1 Answers

You've put the closing parenthesis before num1 and num2, so they're not being passed to printf. You need to change this:

 printf("num1:%d , num2:%d\n"), num1, num2;

to this:

 printf("num1:%d , num2:%d\n", num1, num2);

Yes, the parenthesis is the only change, but it's crucial.

like image 81
Jerry Coffin Avatar answered Dec 05 '22 01:12

Jerry Coffin