How to understand the logic behind the assignment of variables?

  1. Get an IDE
  2. Read a book. Google. Don’t ask questions without researching for an existing solution. I know it’s easy to ask, but researching can help you more than just getting your answer.

Now to your answer. Perhaps, https://www.cprogramming.com/tutorial/c/lesson1.html
Scroll down, read about variables.

Variables are declared as:

int a; 
int b;
int c;

Variables can also be declared all in one line,

int a, b, c;

You could also assign values to your variables when you declare them.

int a = 1;
int b = 2;
int c = 3;

Or, you could declare & assign them values all in one line:

int a = 1, b = 2, c = 3;

The “int” above, is a datatype. It tells the compiler what kind of variable you are declaring. There are various datatypes in C: int, float, char, double, etc. These are the fundamental data types. There also derived datatypes, etc, etc, etc.

If you do not assign a value to a variable, and you just print it, it will print a junk value (in your case 0, it can be anything though). Try assigning values in your method #2 as I did above and you will see the difference.

The return 0, is used to specify the exit code of your application. 0 means the application exited successfully. In case of failure, a value other than 0 is returned, but anyways.

Good luck.
Learn to use google.

Leave a Comment