Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
437 views
in Tutorial & Interview questions by Goeduhub's Expert (9.3k points)

1 Answer

0 like 0 dislike
by Goeduhub's Expert (9.3k points)
 
Best answer

 C programming language was invented by Dennis Ritchie at the Bell Laboratories in 1972.  C was invented to write an operating system called UNIX. C programming is considered as the base for other programming languages, that is why it is known as mother language.

  • Easy to learn

  • Structured language

  • It produces efficient programs

  • It can handle low-level activities

  • It can be compiled on a variety of computer platforms

  • It is widely used in the software development field

Execution of C Program 

C is a compiled language. A compiler is a special tool that compiles the program and converts it into the object file which is machine readable. After the compilation process, the linker will combine different object files and creates a single executable file to run the program.  Flow given below-


Writing a source Code --->Compiling a source code --->Linking Object-files

(test.c)                                (test.obj or test.o)                  (test.exe)


Structure of a C Program

Include header file section 

Global declaration section 

main()

{

Declaration part

Executable part

}

User-defined functions

{

Statements

}


  • C program depends upon some header files for function the definition that is used in the program. Each header file by default is extended with .h. The header file should be included using # 
  • Some variables that are used in more than one function. These variables are known as global variables. This section must be declared outside of all the functions.
  • Every program written in C language must contain main () function. The function main() is a starting point of every C program. The execution of the program always begins with the function main (). 

First C Program, open the C console and write the following code:

#include <stdio.h>    

int main(){    

/* My First C Program */

printf("Hello World");    

return 0;   

}  

  •  Header #include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h .
  • int main() The main() function is the entry point of every program in c language.
  • The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
  • printf() The printf() function is used to print data on the console. The message "Hello World" to be displayed on the screen.
  • return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for successful execution and 1 for unsuccessful execution.

How to Compile and run C Program 

Type 1- First install gcc compiler and then save code in a file like "first.c"

  • Open a command prompt and go to the directory where you have saved the file.

  • Type gcc first.c and press enter to compile your code

  • If  code is error free, the command prompt will take you to the next line and would generate a.out executable file.
  • Now, type a.out to execute your program. You will see the output "Hello World" printed on the screen.

$ gcc hello.c
$ ./a.out
Hello World

Type-2 If you are working in Turbo C++ IDE  or in DeV C then,

By menu, click on the compile menu then compile sub menu to compile the c program.

Then click on the run menu then run sub menu to run the c program.

By shortcut, press ctrl+f9 keys compile and run the program directly.

You will see the output on user screen. 

You can view the user screen any time by pressing the alt+f5 keys.

Now press Esc to return to the turbo c++ console.

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

0 like 0 dislike
1 answer 383 views
0 like 0 dislike
1 answer 430 views
0 like 0 dislike
1 answer 596 views
0 like 0 dislike
1 answer 440 views
0 like 0 dislike
1 answer 364 views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory
...