C Programming

DataTypes

Data types is , store, and manipulate data in the program. There are various types of data to support depending on the type of logic that you are performing in the program. C Language supports a lot of types of data types mainly classified as primary datatypes, derived data types, and user-defined data types

  • Primary data types are those fundamental to C programming language and are mostly straightforward to use (they are int, char, float, and void).
  • Derived data types are primitive data types forming new data structures called arrays, functions, and C pointers.
  • User-defined data types are defined by users and are usually a combination of data types or heterogeneous data types
Primary Data Types

Example :- 

Int is used to hold whole numbers and can take values like zero, positive, or negative, but it can’t contain negative values. 

Float and double are used to hold real numbers, and they differ from each other in byte size. Similarly, int also can handle longer and shorter ranges, which are called short and long
Derived Data Types

Example : -  

Array can contain a homogenous set of primitive data types like int, float, or double.

Function are both user-defined and standard library functions like scanf(), printf(), gets() and puts().
User Defined Data Types

Example : - 

struct student

 {
  char name[100];
  int studId;
  char grade;
 }

Variable

As we are discussing about datatypes, the most important thing to be addressed is Variable. This is a place where values are defined for a computation and its values varied during the course of program execution. The values type defined by the dataTypes.

The values vary during the computation through an assignment The variable can be made using sequence of characters. The sequence /naming can follow different naming convention which will make the variable explanatory/descriptive about its purpose. the syntax for defining , initializing as well as assigning will be as follow

Declaration

Syntax

DataType variableName;

Example : - 

int age;
Initializing

Syntax 

DataType variableName=values

Example: -

int age=34
Assignment

Syntax

variableName = value;

Example: - 

age=34

Constant

It is not variable since its value is not changed during the course of the program execution. The declaration , initialization can be made in the same manner as variable. the declaration and initialization can be made in the same line using a keyword const. The syntax will be as follow

Declaration and initialization
const dataType variableName=value;

Example : - 
const float pi=3.14;

Operators

They are mathematical or logical operations symbols used to do a computation on data. The computation using the operator adhered the precedence rule that is inlace in any mathematical and logical computation. The operators are classified into the following main classes

  • Arithmetic Operators [ +,-,/, *, %]
  • Relational Operators [>,<,>=,<=,==,!=]
  • Logical Operators [ AND, OR, NOT]
  • Bitwise Operators [&,|,^, ..]
  • Ternary or Conditional Operators [condition ? <expression if true> : <expression if false>]
  • Assignment Operator [ =]

Control Statements

These are statements that are mainly used to define the flow or the order in which the steps or instructions need to be executed in the running program. They perform the task of decision making, depending on the conditions or inputs specified to or in the program. In the control statement, various kinds of actions are performed to determine the flow of execution. some of the actions are the follow

  • Decision making : – Can make Decision and decide the flow of the program based on logical conditions like ORAND, and NOT.
  • Selection – Using switch keywords, If the condition specified in the case keyword is met.
  • Iteration : – Are looping statements whiledo-whilewhile do, and for loop to iterate and perform the actions more than one times.
  • Jump : – Are GOTO statements to execute a certain code in particular place.

Console Keywords

Keywords are reserved words in the programming language that is in use. The keywords can not be used to name variables or function. There are various types of keywords to handle different kinds of operation in our program development. In our discussion of keyword, we will consider those working with console like scanf, and printf mainly used to read data from keyboard and write value to console.

scanf

This is a keyword that is used to read data from a keyboard. The keyword has some syntax to follow ignorer to use. The implementation of the scanf refer mainly two things datatype, and variable. The implementation will be as follow

Syntax: -

scanf("%d", &variableName);  

Example: - 
int age=0;

printf("Insert the age");
scanf("%d",$age);
printf("The age is = %d", age);

printf

This is another keyword used to print out value to console. The implementation printf keyword has syntax to follow to display the values to console. The syntax. contains datatype as well as variable. The implementation will be as follow

Syntax :- 

printf("Text to display = %dataType", variableName);

Example: - 

int age=14;
printf("Number = %d", age);

Note : - %dataType can have value [%d,%f,%c,%lf referring integer, float, character, double,..]
Scroll to Top