C Programming
C Programming

C notes from scratch to advance | Variable , Constants and Keywords in C | #C

C notes from scratch to advance | Variable , Constants and Keywords in C | #C

C Programming
C Programming

Variables

A variable is a container which stores a ‘value.’

Let me explain this with an example : In the kitchen, we have containers storing rice, dal, sugar, etc.

Similar to that variable in C stores the value of a constant. That value may be different as in kitchen dal , rice and all here we may have Int , Double , String and Float , etc. We will definitely know these all in brief.

Example: 

a = 3 a is assigned “3”
b = 4.7 b is assigned “4.7”
c = ‘A’ c is assigned “A”

Rules for naming variables in c:

1. The first character must be an alphabet or underscore( _ ).

2. No commas or blanks are allowed.

3. No special symbol other than underscore is allowed

4. Variable names are case sensitive ( ie: rAm and ram are two different variable )

Definitely we can use a , b , c , d or any random and meaningless things as a name. But I will recommend you to use and create meaningful variables names in our programs. This enhances readability of our programs.

Constants

An entity whose value doesn’t change is called a constant.

or

A data or value which doesn’t change during a whole program are called a Constants.

Types of constant

Primarily there are three types of constant :

1. Integer Constant -1,6,7,9
2. Real Constant -322.1,2.5,7.0
3. Character Constant ‘a’,’$’,’@’(must be enclosed within single inverted commas)

Keywords

These are reserved words whose meaning is already known to the compiler.

or

Any reserved words for C are called Keywords.

There are 32 keywords available in C :

auto double int struct
break long else switch
case return enum typedef
char register extern union
const short float unsigned
continue signed for void
default sizeof goto volatile
do static if while

 

Our first C program : 

#include<stdio.h>

int main() {

printf(“Hello, I am learning C with Harry”);
return 0;

}

The basic structure of a C program 

All C programs have to follow a basic structure called syntax.

As we have rules and regulations in every field either its traffic laws or tax rules. Simply their are some set of rules in C or in simple word we have a defined rules for C program called “Syntax“.

Example : A C program starts with the main function and executes instructions presents inside it. Each instruction terminated with a semicolon(;)

  • There are some basic rules which are applicable to all the C programs:
    • Every program’s execution starts from the main function.
    • All the statements are terminated with a semi-colon.
    • Instructions are case-sensitive.
    • Instructions are executed in the same order in which they are written.

Comments 

Comments are used to clarify something about the program in plain language. It is a way for us to add notes to our program. There are two types of comments in c:

  • Single line comment:
    • //This is a single-line comment.
  • Multi-line comment :
      • /*This is multi-line comment
      •     This is multi-line comment
      •     This is multi-line comment
      •     This is multi-line comment
      •     This is multi-line comment*/

Comments in a C program are not executed and ignored. Compiler simply skips the comments and move forward.

Compilation and execution

A compiler is a computer program that converts a C program into machine language so that it can be easily understood by the computer.

A program is written in plain text. This plain text is a combination of instructions in a particular sequence. The compiler performs some basic checks and finally converts the program into an executable.

Library functions

C language has a lot of valuable library functions which is used to carry out a certain task; for instance, printf function is used to print values on the screen.

printf(“This is %d”,i);

// %d for integers

// %f for real values

// %c for characters

Types of variables

Integer variables int a=3;
Real variables int a=7.7 (wrong as 7.7 is real) ; float a=7.7;
Character variables char a=’B’;

 

Receiving input from the user

In order to take input from the user and assign it to a variable, we use scanf function.

The syntax for using scanf:

  • scanf(“%d”,&i); // [This & is important]

& is the “address of” operator, and it means that the supplied value should be copied to the address which is indicated by variable i.

 


Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.

Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.

 

🧑‍💻🧑‍💻 Social Media Links of Tech DCode :
👉🏻 YouTube : https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
👉🏻 Instagram : https://www.instagram.com/thetechdcode/
👉🏻 Facebook Page : https://www.facebook.com/thetechdcode
👉🏻 Twitter : https://twitter.com/thetechdcode
👉🏻 Telegram Channel : https://t.me/thetechdcode
👉🏻 Tech DCode Linktree : https://linktr.ee/thetechdcode
👉🏻 My Personal Handles : https://linktr.ee/virtualshivamin

🧑‍💻🧑‍💻 Social Media Links of SHIVAM SINGH (OWNER) :
👉🏻 Instagram : https://www.instagram.com/virtualshivamin/
👉🏻 Facebook Page : https://www.facebook.com/virtualshivamin/
👉🏻 Twitter : https://twitter.com/virtualshivamin/
👉🏻 Personal Linktree : https://linktr.ee/virtualshivamin 

 


 

Leave a Reply

Your email address will not be published. Required fields are marked *