INTRODUCTION TO C - PROGRAMMING LANGUAGE

Dev Frank
6 min readDec 31, 2023

--

Dev Frank

C is a high, general-purpose programming language. It was founded by Dennis Ritchie 1972 in BELL LABORATORIES, New Jersey, U.S.A .

What is C?

C is probably the most widely known programming language. It’s probably the language that people learn the most in school among with Python and Java.

PNGWING

Currently, C plays a prominent role in embedded devices and serves as the backbone for the majority of Internet servers, particularly those operating on Linux. Notably, the Linux kernel and, by extension, the core of all Android devices are constructed using C. In essence, C code is running extensively across the globe, making its impact significant and noteworthy.

C is a language, just like English or French, but it’s a language that computers understand. People use this language to tell computers what to do.

Upon its inception, C earned its high-level language status due to its portability across machines. While today we take cross-platform compatibility for granted, C’s simplicity and easy compiler portability were groundbreaking in an era where running a program seamlessly across different systems was far from common. C, akin to Go, Java, Swift, or Rust, is a compiled language — unlike interpreted languages such as Python, Ruby, or JavaScript. The distinction lies in the generation of a directly executable binary file in compiled languages. Notably, C lacks garbage collection, demanding manual memory management. This intricacy, while posing challenges in bug prevention, renders C well-suited for programming embedded devices like Arduino. C, unapologetically exposing the intricacies and capabilities of the underlying machine, offers immense power once one grasps its potential.

Computer Instructions: Imagine your computer is like a really smart but obedient friend. However, it only understands a specific set of instructions. C helps you communicate those instructions to make the computer perform tasks.

How Does It Work?

Writing Commands: In C, you write commands or instructions that the computer can understand. These commands are like recipes that tell the computer what steps to follow.

Organized Steps: C allows you to organize these steps neatly. For example, if you want the computer to say “Hello,” you write a command for that, and C helps you arrange it properly.

#include <stdio.h>              // It is a header file,that defines the 
// input/output routines used by our program

int main(void) // starting point of our program
{
printf("Hello World!\n"); // is the command to print "Hello, World!"
// on the screen.

return (0); // says that everything went well.
}

int

The int represents the output of the function. It is a datatype of 4bytes / 2bytes (It varies in local machines).

main ()—

It is a function. The main function in the above code returns an int (integer value). It takes an argument void. This is the starting or entry point of our program. It indicates that the function takes no argument.

void —

It is an argument. Void is a datatype, in c language means there are no arguments in the specified program.

{ —

The opening curly brace { marks the beginning of the main function's body. Everything between { and } is part of the function.

printf —

The printf function is from the stdio.h library and is used to print formatted output to the console. It prints out whatever we it to i.e. it’s going to print out whatever is in the parenthesis ( ) and enclosed in a double quote(“ ”).

“Hello World” —

This is a string. Anything enclosed in a double quotes (“ ” ) is called a string.

\n —

It is an escape character that means a newline i.e. we want a newline to be added after the text (“Hello World”) is printed.

return (0) —

  • The return statement indicates the end of the main function and returns a value to the operating system.
  • (0) means the program has executed successfully. A non-zero value usually indicates an error.

} —

The closing curly brace } marks the end of the main function's body.

C is a very small language at its core, and anything that’s not part of the core is provided by libraries. Some of those libraries are built by normal programmers, and made available for others to use. Some other libraries are 6 built into the compiler. Like stdio and others. stdio is the libraries that provides the printf() function.

WHY DO WE WRITE PROGRAMS?

Computer is a general purpose machine, which can perform any computational task. Computer does not understand your language (English, French, Spanish etc.), so we write some instructions or commands i.e. sequence of instructions or commands. We give that instructions to the computer. These commands are like recipes that tell the computer what steps to follow. So according to the instructions the computer can perform our task(s).

So we can say

A program is / are set of instructions given to a computer to perform a specific task. The language of the computer is binary i.e. zeros and ones. Computer runs by program.

N.B — Software are set of programs

Before C, there was a language called B-language i.e. C language was the successor of B language. The B language was developed by Ken Thompson. The C-programming language was used to write the Unix / Linux operating system.

We can also say C-language is a system programming language. It was standardized by ANSI in 1989. It is also called a compiled language because after you must have written your program in C-language, the compiler has to compile it to object code or machine code (ones & zeros).

HOW TO DO WE WRITE AND EXECUTE PROGRAMS?

Picasa

Is not that we write programs in simple language like English language for the computer to understand. We need programming languages like C-programming language.

Writing programs in C involves several steps. Here’s a simple guide to get you started:

Set Up Your Development Environment:

1. Install a C Compiler:

Examples include GCC (GNU Compiler Collection), Clang, or a compiler included with an integrated development environment (IDE) like Code::Blocks, Dev-C++, or Visual Studio.

Choose a Text Editor or IDE:

Use a text editor like Notepad, Visual Studio Code, Sublime Text, or an IDE like Code::Blocks, Dev-C++, or Visual Studio.

2. Create a New C File:

  • Open your text editor or IDE.
  • Create a new file with a .c extension, for example, my_program.c.

3. Write Your C Code:

  • Start by including necessary header files. For a simple program, you’ll need #include <stdio.h> for input/output functions.
  • Write the main function, the starting point of C programs.

Example “Hello World” Program:

#include <stdio.h>

int main() {
printf("Hello, World!\n");
return 0;
}

4. Save Your File:

  • Save your C file with a .c extension.

5. Compile Your Code:

  • Open a terminal or command prompt.

As mentioned, C is a compiled language. To run the program we must first compile it. Any Linux or macOS computer already comes with a C compiler built-in. For Windows, you can use the Windows Subsystem for Linux (WSL).

  • Navigate to the directory where your C file is saved.
  • Use the following command to compile: (Assuming you have GCC installed)
gcc my_program.c -o my_program

This command tells GCC to compile my_program.c and create an executable named my_program

6. Run Your Program:

  • After successful compiling, you’ll get an executable file (e.g., my_program).
  • Run it using:
./my_program 

7. View Output:

  • You should see the output of your program on the screen. In the case of the “Hello, World!” program, it will display:
Hello, World!

Congratulations! You’ve successfully executed a C program.

8. Debugging:

  • If your program has errors, the compiler will provide error messages.
  • Pay attention to any error messages during compilation. Fix errors before attempting to run the program.
  • Read these messages to identify and fix issues.
  • You can use print statements (printf) for debugging.

After you must’ve been done with writing your program in C-language or any language. The program has to be converted into MACHINE LANGUAGE (binary) and computer will execute your program i.e. the C.P.U because it is the central processing unit. The C.P.U is responsible for giving you an output.

Quiz!!!

  1. Question: What is the purpose of the printf function in C, and how is it used to display output on the screen? Provide a simple example.
  2. Question: Explain the role of the main function in a C program. Why is it considered the starting point, and what does its return value signify?
  3. Question: Why is the #include <stdio.h> statement commonly used in C programs? What essential functionality does it bring to your code?

--

--

Dev Frank

Passionate tech enthusiast, diving deep into the world of software engineering. Thrilled to share insights with the world. A Software engineering student.