INTRODUCTION FOR C

Maha


Introduction For C

  • C programming is a general-purpose, programming language that has been widely used for developing system software, embedded systems, and many other applications.
  • It was developed by Dennis Ritchie in early 1972 at Bell Laboratories and since, it become one of the most popular programming languages in the world.
  • System-level tasks like bit-level operations, direct hardware access, and low-level memory manipulation are all handled by this powerful set of features. 
  • In addition, there are a lot of standard libraries for C that help with input/output, string manipulation, and mathematical operations.

Difference Between C And C++ 

  • C++ was developed as an extension of C, both languages have almost the same syntax.
  • The main difference between C and C++ is that C++ support classes and objects, while C does not.

How To Start C Programming

Two way to start C programming:
  1. A text editors like notepad, to write C program.
  2. A compiler, like GCC (GNU compiler collection) to translate the c program to computer language.
  3. Extension for file to save as file_name.c

How To Install GCC In Ubuntu

The default Ubuntu repositories contain a meta-package named build-essential that contains the GCC compiler and a lot of libraries and other utilities required for compiling software.
 

Perform The Steps Below To Install The GCC Compiler In Ubuntu:  

1. Open terminal (Ctrl + T)


2. Type command in terminal. Start by updating the packages list.

$ sudo apt update



3. Install the build-essential package by typing.

$ sudo apt install build-essential


The command install a bunch of new packages including gcc, g++ and make.

You may also want to install the manual pages about using GNU/Linux for development.

$ sudo apt-get install manpages-dev


4. To validate that the GCC compiler is successfully installed, use the gcc --version command which prints the GCC version.

$ gcc --version


How To Run C Program

=> Now open text editor.


=> Type simple C program in Text editor:

Program:


#include <stdio.h>
int main() {
    printf("hello world");
    return 0;
}


Output:


hello world




=> Then you will save file as myfirstprogram.c



=> After save this program to open terminal in your program directory.


=> Type command to compile the program.

$gcc myfirstprogram.c -o myfirstprogram


=> After compile a C program then you will type command.

./myfirstprogram


=> Program  will be successfully executed.

Some Of The C Header Files:

stdio.h – It defines standard input and output.
stdint.h – It defines exact width integer types.
stdlib.h – It defines standard library.
string.h – It defines string handling functions.
conio.h _ It defines console input and output.

Structure Of C Program

Program 1:


#include <stdio.h>
int main(){
     printf("My C program");
     return 0;
}



Output:


  My C program


Program 2:


#include <stdio.h> 
int main() 
    int a = 30; 
    printf("%d", a); 
    return 0;   
}


Output:

 
  30





More topic in C

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send