Intro
C is a powerful and widely-used programming language that has been around since the early 1970s. It was developed by Dennis Ritchie at Bell Labs and has since become one of the most influential programming languages in the history of computing. C is known for its efficiency, portability, and low-level access to memory, making it a popular choice for system programming, embedded systems, and performance-critical applications.
C is a compiled language, which means that the source code you write in C is transformed into machine code that can be executed directly by the computer’s hardware. This allows C programs to run very fast and efficiently, making it ideal for applications where performance is a concern.
C is not an object-oriented language, but it provides a rich set of features that allow programmers to write structured and modular code. It supports functions, pointers, and dynamic memory allocation, which gives developers a lot of control over how their programs manage resources.
C is not garbage collected, which means that programmers are responsible for managing memory manually. This can lead to issues such as memory leaks and buffer overflows if not handled carefully, but it also allows for greater control and efficiency in memory usage.
Example of a simple C program:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
In this example, we include the standard input/output library stdio.h, which allows us to use the printf function to print “Hello, World!” to the console. The main function is the entry point of the program, and it returns 0 to indicate that the program finished successfully.
How do we execute a C program?
To execute a C program, you need to follow these steps:
-
Write your C code in a text editor and save it with a
.cextension, for example,hello.c. -
Open a terminal and navigate to the directory where your C file is located.
-
Compile the C program using a C compiler like
gcc. You can do this by running the command:gcc hello.c -o helloThis command compiles
hello.cand creates an executable file namedhello. -
Finally, you can run the compiled program by executing:
./helloThis will execute the
helloprogram, and you should see the output “Hello, World!” in the terminal.