Fundamentals of C Programming

Here we will discuss the fundamentals of C Programming. We deal with Data Types, Several types of Operators, Expressions, Constants, and Variables with their types & examples.

Data Types in C

Data types are declarations for variables. A data type is a keyword that is used to define the value of a variable stored in memory. There are two types of data types:

  • Fundamental or basic data type
  • Derived data type

Fundamental data types

These are the data type which are already specified in the compiler. A fundamental data type is also called basic data type.

There are three basic data type. They are char, int and float.

Int data type

It is the data type used to declare the variable which store the integral value i.e. full number without Frictional part.

This data type occupies the two-byte memory space in the 16-bit operating system. If the operating system is 32 bit it occupies the 4-byte memory space. And its range size is 0-255 or -128 to 127.

Example: int x;

Char data type

Char data type is used to declare the variable which can store single character or the string variable.

It can occupy the 1 byte memory space in the 16 bit operating system. And its range is from -128 to 127.

Example: char ch;

Float data type

A float data type is used to declare the value of the variable which stores the numerical value with the fractional part. It can store the number with the fraction of six-digit after the decimal point.

It can occupy 4 bytes of memory space and its range is from -231 to 230.

Example: float price;

Some Other data Types in C are:

  • double
  • short int
  • unsigned int
  • long int
  • long long int
  • unsigned long int
  • unsigned long long int
  • signed char
  • unsigned char
  • long double

Derived data types

The data type which is defined by the user according to the need, is called derived data types.

Derived data types are made by using basic data types to perform certain tasks. Array, string, structure, union are the derived data types.


Constants & Variables in C Programming

Constants

Constant are those, whose value cannot be changed during the execution of a program. There are four types of constant namely: integer constant, real constant, string constant, and character constant.

Numeric constant: The numeric constant has numeric values. i.e. int, float, etc. An integer can be a decimal, octal, and hexadecimal constant.

Char constant: Character constant is a single character enclosed in apostrophes. Example:  ‘A’, ‘C’ ,’#’

String constant: String is a set of the character enclosed in double-quotes. For example “Informer Guru”  is a string. A character constant (eg ‘A’) and the corresponding single-character string constant are not equivalent.

Symbolic constant: The constant that represents the name in your program is called the symbolic constant. C has two methods for defining the symbolic constant using: #define directives & constant keyword.

As we know the PI is constant with value 3.1 436 and we define it in C using the constant keyword.

Example: constant float PI=3.14;

Variables

Variables are used to store the value of a variable. They are also used as references to the memory. The value of the variable changes during the execution.

The naming rule for the variable is as follows:

  • A variable must start with an alphabet.
  • A keyword is not used for the variable name.
  • No special symbols are used except underscore.
  • Upper case and lower case have different meanings such as AREA and area have a different meaning.
  • Same name of two variables can’t use in the same program i.e. there is a unique variable in the program.

Example: int playerScore = 95;

Here, playerScore is a variable of int type. And it is assigned an integer value of 95.


Operators and Expressions in C Programming

Operators

The operator is the special symbol that is used to perform the computational task. There are many types of operator used in c programming some of widely used operators are are given below:

  • Arithmetic operator
  • Comparison operator
  • Logical operator
  • Assignment operator
  • Increment and decrement operator

Arithmetic operator

These are the operator which is used to perform an arithmetical operation. The arithmetic operators used in C programming are as follow:

Operator  Meaning
+ Addition
Subtraction
*  Multiplication
/  Division
% modulus (reminder)

Comparison operator (Relational Operator)

These are the operators which are used to compare two or more operand and a provide a specific result. The comparison operators used in the C are as follow:

Operator Meaning
> greater than
>= greater than equal to
Less than
<= less than equal to
= = equal to
!= not equal to

Logical Operator

Logical operators are used to connect the two or more expression and provided a result as a single expression. The logical operator used in C are as follow:

Operator Meaning
&& logical AND
││  Logical OR
 ! Logical NOT

Assignment operator

The assignment operator is the operator which assigns the value of its right side to its left side. The assignment operator is ‘ =’.

Increment and decrement operator

This type of operator is the unary operator because it is used with a signal operand. This type of operator is used to increase or decrease the value of the variable by 1. For Example: a++, b–, etc


Expressions

An expression is a combination of variables, constants, and operators written according to the syntax of the C language.

In C, every expression evaluates to a value. Some examples of C expressions are shown in the table given below.

Algebraic Expression C Expression
a x b – c  a * b – c
(m + n) (x + y) (m + n) * (x + y)
(ab / c) a * b / c
3×2 +2x + 1 3*x*x+2*x+1

Print Friendly, PDF & Email

Leave a Comment

Hey, wait!Get Regular Update's

Subscribe Stay Connected, Keep Learning!