Lets' try to understand Variables and Data Types of "C Programming"

Before we going to start lesson of variables we need to know about keywords and identifiers in C programming.

Keywords are predefined, reserved words used in programming that have special meanings to the compiler.
We told you in previous lessons, C is a case sensitive language so all the keywords must be written in lowercase.
Ex; case, char, const, for, do, double, int, long

What about Identifiers?

An identifier in C consists of a sequence of letters, digits, or underscore characters.
Identifiers are use  when we assign variables, arrays, enumerations, structures, union, typedef and functions.
There are some rules for using identifiers;

1. A valid identifier can have letters, digits and underscores. 
2. The first letter of an identifier should be either a letter or an underscore.

Variable;

In C programming, a variable is a named storage  location that holds a value. It allows for the manipulation of data within a program and provides a way to store information.
We can't use keywords as variables.
Variable can be used to store integers, floating point numbers, characters and also strings to locations inside the computer's memory.

There are some rules that you must need to know.

1. They must begin with a letter or underscore.
    (sum, a, ABC, Unit_price, _place, _123)
2. Can't use any special  characters or symbols (total$value)
3. Can't use spaces(total price)
4. Can't start with a number(123)
6. Can't use keywords (int, char)

What are the valid variables?

1.sum                    
2.unit price
3_value
4.Price
5.#name 
6.1st_number 

Comment your answer and write the reason for it in the comment section.

Data Types;

In C programming, a variable is a symbolic name associated with a memory location that stores data. It enables manipulation and storage of values, and its type determines the kind of data it can hold, such as integers, floating-point numbers, or characters.

In C programming language there are int, float, and char as basic data types.

  • int - For storing Integral numbers
  • float - for storing floating point numbers
  • char - for storing single character   
  • double - for storing double precision floating point  numbers.
  • _Bool - For indicating an on/off, yes/no, or true/false situation. 

Constants;

In C, any number, single character, or character string is known as a constant.
There are 5 types of constants:
  • Integer Constants - sequence of digits, optionally preceded by a  plus or minus sign.%i, %o, %x are the print format characters in integer constants.
  • Floating point constants - A floating-point constant consists of a sequence of decimal digits, decimal point, and another sequence of decimal digits.%f, %e are the print format characters in floating point constants.
  • Character constants - A character enclosed within single quotation marks is a character constant. %c is the print format character in character constants.
  • Character string constants - A sequence of zero or more characters enclosed within double quotation marks represents a character string constant. %c is the print format character in character string constants.
  • Enumeration constants 
That's the end of introduction to variables and data types in C programming. I hope you will Understand what is KEYWORD, IDENTIFIRE, VARIABLE and DATA TYPES in C programming.
In next Step we will discuss about  Variable Declaration.


#ICT #Programming

Post a Comment

Previous Post Next Post