C Variables and Definition

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/c-variables-definition/
PINTEREST
PINTEREST
INSTAGRAM

C Programming Tutorial Index

  1. Introduction To Programming
  2. C Setup Development Environment
  3. C Hello World and Compile First Application
  4. C Syntax and Basics
  5. C Variables
  6. C Numeric Variable Types (Integer, Long, Float)
  7. C String Variables
  8. C Constants and Define Processor
  9. C Operators
  10. C If Else and Switch Case Conditionals
  11. C While Loops
  12. C For Loops
  13. C Arrays
  14. C Functions
  15. C Structure
  16. C Union
  17. C File Operations (Open, Read, Write)
  18. C Pointers
  19. C Type Casting
  20. C Header Files and Include

Most important function is storing data while the application running. The data may be  age, username, picture, full name etc. To hold data variables are used. Variables are stored in the memory. After application run all variables are cleaned. So variables do not persists between application runs. As variables stored in memory they need some space in the memory but how much? This memory size can change according to data type or variable type.We will look variable types below. Say we have a string like “Hello poftut” and as number 1 . They will occupy different lengths of memory. Knowing this is enough for now.

Syntax

We have already seen syntax of C programming language but look again will make learning better. Below is a syntax which is the same with statement to define a variable.

Here type is the type of variable as we stated before. Because there are different type of data like number, string, floating-point etc. Types are differentiated to make C programming language more efficient and fast. If all data were same type there will be a lot of casting or type guessing  to operate on them.

Here we will define a variable that holds age.

LEARN MORE  Python Modules Tutorial With Examples

int is our variable type and age is our variable or variable name which will hold the age data.

Set Value

Just defining a variable is not enough because we want to hold data on variable. Here is how can we do this

In this line there is two step. One step is defining an int variable named age . Second is assigning 25 to the this variable named age .

An other way to set value is after definition. So we learned that we have no obligation to set data on the variable definition.

Define Multiple Variables

We can define multiple variables in a single shot to make it easy and readable like below. This is called as multiple variable definition with single statement.

All of these variables named ageyear, length are integer type are defined in a single statement. We will look variable type next chapters.

Define and Assign Multiple Variables

Now we merge what we have learned and define multiple variables in a single line by setting values to them.

C Programming Tutorial Index

  1. Introduction To Programming
  2. C Setup Development Environment
  3. C Hello World and Compile First Application
  4. C Syntax and Basics
  5. C Variables
  6. C Numeric Variable Types (Integer, Long, Float)
  7. C String Variables
  8. C Constants and Define Processor
  9. C Operators
  10. C If Else and Switch Case Conditionals
  11. C While Loops
  12. C For Loops
  13. C Arrays
  14. C Functions
  15. C Structure
  16. C Union
  17. C File Operations (Open, Read, Write)
  18. C Pointers
  19. C Type Casting
  20. C Header Files and Include
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/c-variables-definition/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.