C Language for Hackers & Beyond! 0x02

Vicky Kumar
InfoSec Write-ups
Published in
5 min readAug 19, 2022

--

Helloooo Hackers, Infosec Professionals and also my dear Programmers it is the next article of the previous one. In this article, we focus on the core concept of C programming.
Before you know about its core concepts or key concepts let’s dive into how a C program look likes.

C program to print some strings.
C program to take input from user and add it.

Hey, don’t fear from the above program you also can do it. It is very simple and easy. You just need to learn it and to learn it be consistent with us to upgrade yourself.

ASCII

ASCII stands for American Standard Code for Information Interchange. It’s a 7-bit character code where every single bit represents a unique character and it is a numerical representation of a character such as ‘a’ or ‘@’ or an action.

There are total 256 ASCII characters. From that 128 are standard ASCII characters and 128 are extended ASCII characters.

For more information about ASCII, Characters visit https://www.ascii-code.com/

Begin Learning C

English is a language to communicate with human to human.
Same as C is also a language that communicates with humans to a computer it is one-way communication means that only humans can give instructions to the computers but computers can’t give any instruction to humans in c programming language.

  • Basic elements of the C language are like as the English language and numbers and also some characters.

eg: a to z, A to Z, 0 to 9, some special characters, and many more……

  • In the English language, we make words from the alphabet same as in the C language we make words that are known as Identifier. It can be the name of any constant, variable, or keyword in the C program.
  • Now we make a sentence with a group of words in English here also we form a sentence that is known as Instructions.

There are 4 types of Instructions in the C language:-

  1. Datatype Declaration Instruction
  2. Input/Output Instruction
  3. Arithmetic Instruction
  4. Control Instruction

Now let’s make a program, and here program is a group of instructions.

Identifier

In C language every word is classified into either a keyword or an identifier.

Identifiers are names given to various program elements like variables or functions.

In C language we always wrote action statements after declaration. An action statement is a statement in a C program that performs some action during the execution of the program.

During, the execution of our program the memory is allocated in RAM for two purposes the first one is to store the instructions of the program and the second one is to store data that are going to be proceed in the program.

The data which are going to process during the execution of program is stored in variables.

Variables in C

A variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times.

It is like as a blank glass in which we puts some value.

It is a way to represent memory location through symbol so that it can be easily identified.

Let’s see the syntax to declare a variable:

data type variable_name;

The example of declaring the variable is given below:

int x ;

float y;

char z;

Rules for defining variables

  • A variable can have alphabets, digits, and underscore.
  • A variable name can start with the alphabet, and underscore only. It can’t start with a digit.
  • No whitespace is allowed within the variable name.
  • A variable name must not be any reserved word or keyword, e.g. int, float, etc.

Types of Variables in C

There are many types of variables in c:

  1. local variable
  2. global variable
  3. static variable
  4. automatic variable
  5. external variable

Local Variable

A variable that is declared inside the function or block is called a local variable.

It must be declared at the start of the block.

void function1(){

int x=10;//local variable

}

You must have to initialize the local variable before it is used.

Global Variable

A variable that is declared outside the function or block is called a global variable. Any function can change the value of the global variable. It is available to all the functions.

It must be declared at the start of the block.

int value=20;//global variable

void function1(){

int x=10;//local variable

}

Static Variable

A variable that is declared with the static keyword is called static variable.

It retains its value between multiple function calls.

void function1(){

int x=20;//local variable

static int y=20;//static variable

x=x+1;

y=y+1;

printf(“%d,%d”,x,y);

}

If you call this function many times, the local variable will print the same value for each function call, e.g, 21,21,21 and so on. But the static variable will print the incremented value in each function call, e.g. 21, 22, 23 and so on

Automatic Variable

All variables in C that are declared inside the block, are automatic variables by default. We can explicitly declare an automatic variable using auto keyword.

void main(){

int x=7;//local variable (also automatic)

auto int y=20;//automatic variable

}

External Variable

We can share a variable in multiple C source files by using an external variable. To declare an external variable, you need to use extern keyword.

extern int x=10;//external variable (also global)

save it as myfile.h

Constants in C

A constant is a value or variable that can’t be changed during the execution of the program, for example: 10, 20, ‘a’, 3.4, “c programming” etc.

In C language, a number or character or string of characters is called a constant. And it can be any data type. Constants are also called as literals.

And this is it for today. ✔️ Enjoy your life with 😃 smile and keep learning and wait for next article…

Feel free to Subscribe for more content 🔔, clap 👏🏻 and share the article With anyone you’d like.

As always, I appreciate your support.

From Infosec Writeups: A lot is coming up in the Infosec every day that it’s hard to keep up with. Join our weekly newsletter to get all the latest Infosec trends in the form of 5 articles, 4 Threads, 3 videos, 2 Github Repos and tools, and 1 job alert for FREE!

--

--

I am an Ethical Hacker 👩‍💻 | Security Researcher 📖 | Open Source Contributor 🤝| Bug Hunter🐞| Penetration Tester💻| Python Lover ❤️ | DevSecOps Explorer 🕵️