Learning C Programming Language - 1

in Programming & Dev2 years ago (edited)

image
Source Image

Hi, today I want to talk about C language. In this post, I want to explain the structure and method of programming with this language so that in the end you will be able to understand and write simple programs.

Structure


The first step in learning any language is to learn and understand the structure of the programs in that language. The general structure of a program in C is as follows.

#include <stdio.h> int main() { printf("Hello World!"); return 0; }
The first thing we do is add libraries to the program. These libraries contain functions or methods that work for us. You don't need to know what is going on behind the scenes, you are just requesting the action you want using the functions or methods inside these libraries and classes.
To join any library, you only need to write the following line of code.

#include <yourlibrary.h>

You can add as many libraries as you want at the beginning of the code, one after the other, with this command.

#include <yourlibrary1.h>
#include <yourlibrary2.h>
#include <yourlibrary3.h>
#include <yourlibrary4.h>

Here, because we want to display a message to the user on the screen, our function is printf() which is in the library stdio.h . So we have to paste this library at the beginning of the code first.
In this case, the compiler will refer to this library and the definition of this function of the program will be pasted, otherwise, in the absence of this library, an error will be issued and your program will not run.

In C language, we have a function called main() that is your main function. All your programs should be written in this function.
When the compiler sees this function, it executes everything inside it, and its absence means that your program will not run.

Rules:

  1. C Compiler is case-sensitive.
  2. All commands end in ;
  3. The body of the program / function starts with { And ends with }

return 0 ends the main() function.

Sort:  

Congratulations @leo32! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You got more than 10 replies.
Your next target is to reach 50 replies.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

Hive Power Up Day - April 1st 2023
Happy Birthday to the Hive Community
The Hive Gamification Proposal
Support the HiveBuzz project. Vote for our proposal!