‘C‘ is a general-purpose programming language developed by Dennis Ritchie at AT&T Bell Labs in the early 1970s. It was designed to be a structured programming language.
The ‘C‘ programming language evolved from the B programming language, which itself was based on BCPL (Basic Combined Programming Language).
While initially created to design the UNIX operating system, ‘C‘ quickly gained popularity due to its efficiency and flexibility, allowing programmers to write various types of software.
‘C‘ is considered a middle-level language, as it combines elements of both high-level and low-level programming languages. It provides access to low-level memory manipulation, but its syntax and structure are similar to high-level languages, making it versatile and efficient.
Why Choose ‘C’ Over Other High-Level Languages?
In today’s world, where languages like Perl, PHP, Java, and others dominate, you may wonder why ‘C‘ is still widely used.
The reasons include:
- Robust: C provides a strong foundation for creating efficient and reliable programs.
- Rich Set of Built-in Functions: C offers a vast library of functions for various operations, making coding easier.
- Supports Low-level Programming: Despite being high-level in syntax, C allows for low-level memory manipulation, making it suitable for system programming.
- Versatile for All Types of Software: C is used to write system software, application software, business applications, and more.
- Efficient and Fast: Programs written in C tend to run quickly, thanks to its powerful operators and a variety of data types.
- Portability: C programs are highly portable, meaning they can run on different machines with minimal changes.
- Extensible and Simple: The language’s simplicity allows developers to easily extend and modify programs. The C standard library provides a rich set of functions to support developers.
- Influential: Many modern programming languages, such as C#, Java, JavaScript, Perl, PHP, and Python, have been influenced by C.
Why Do Most Programming Courses Start with ‘C’?
‘C‘ is often the first programming language taught in computer science courses due to its simplicity, efficiency, and the ability to teach fundamental programming concepts like memory management and the use of pointers.
These skills are transferable to other programming languages, making ‘C‘ a crucial language for anyone pursuing software development.
‘C’ in the Real World
Did you know that 90% of the world’s supercomputers run Linux? Linux, which forms the backbone of many servers, smartphones, and even space exploration systems, is primarily written in C. The Linux 3.2 kernel alone had over 15 million lines of code, showcasing the power and relevance of C in modern software.
A single ounce of practice is worth more than tons of theory. The best way to learn to program is by writing your own code. Don’t just copy-paste code – practice by creating your own programs and learning from your mistakes.
Anatomy of a C Program
Let’s break down a simple C program:
The #include
directive tells the compiler where to find external code files, usually header files (.h)
containing function prototypes. The content of these files is copied into your program during compilation.
#include <file>
: System-defined header files.#include "file"
: User-defined header files.
Every C program must have a main()
function, which is the entry point of the program. It is where the execution begins. There can only be one main()
function in a program.
int main(void) { // Your code here return 0; }
In the following program, a
, b
, c
, and add
are variables used to store integer values.
Example 1: Adding Three Numbers
#include <stdio.h> int main() { int a, b, c, add; printf("Enter the first number: "); scanf("%d", &a); printf("Enter the second number: "); scanf("%d", &b); printf("Enter the third number: "); scanf("%d", &c); add = a + b + c; printf("%d + %d + %d = %d\n", a, b, c, add); return 0; }
To compile and run the program:
- Save the program as f
irst_prog.c
- Compile with the command:
gcc -o first_prog first_prog.c
- Run with:
./first_prog
Note: C is not case-sensitive, meaning main()
is equivalent to Main()
.
Example 2: Calculating Powers of 2
#include <stdio.h> #define N 16 int main(void) { int n; int val = 1; printf("\t n \t 2^n\n"); printf("\t================\n"); for (n = 0; n <= N; n++) { printf("\t%3d \t %6d\n", n, val); val = 2 * val; } return 0; }
Example 3: Finding Factors of a Number
#include <stdio.h> int main(void) { int n, lcv, flag; printf("Enter value of N > "); scanf("%d", &n); for (lcv = 2, flag = 1; lcv <= (n / 2); lcv++) { if ((n % lcv) == 0) { if (flag) { printf("The non-trivial factors of %d are: \n", n); flag = 0; } printf("\t%d\n", lcv); } } if (flag) { printf("%d is prime\n", n); } return 0; }
Example 4: Fibonacci Series
#include <stdio.h> int main(void) { int n, i, current, next, twoaway; printf("How many Fibonacci numbers do you want to compute? "); scanf("%d", &n); if (n <= 0) { printf("The number should be positive.\n"); } else { printf("\n\n\tI \t Fibonacci(I) \n\t=====================\n"); next = current = 1; for (i = 1; i <= n; i++) { printf("\t%d \t %d\n", i, current); twoaway = current + next; current = next; next = twoaway; } } return 0; }
What if ‘C’ Never Existed?
Imagine a world without C. There would be no Linux, no macOS, no Windows, no smartphones, no microprocessors, and possibly no computers as we know them. ‘C‘ has had a profound impact on modern computing, influencing many other languages and technologies.
Conclusion
In conclusion, to truly master programming, practice is key. Write your own code, tackle problems, and experiment with ideas. If you run into trouble, don’t hesitate to seek help or consult resources like Tecmint for up-to-date information.
Remember, learning ‘C‘ is a stepping stone to understanding many other programming languages, and its influence on the software we use every day is undeniable.
Very nice intro. Was looking for something like this.
If C wasnt around they would have coded the linux kernal in Cobol or Lisp as they are still really great. C was used as it was invented as a systems programming language and was largely untested until unix was made and improved over time. C matured as a result of unix large scale adoption. Lisp was already more fully featured and had and still has more features than C. A kernel in lisp would have been better actually.
Hey Avishek,
The great Dennis Ritchie is Dennis, not Dennise (Please alter your graphic so that he doesnt sound like the mother of C and UNIX) :)
Raja: Most if not all those languages you mention are written in C and are interpreted and so by definition slower than ‘C’. If you are writing CGI the C is probably NOT suitable.
Kind regards
mistere
Yeah! sorry for that, corrected now.
Yep.
Pascal has all of the advantage of C, and is far more readable :)
Is there anything that can match Free Pascal’s ‘Lazarus’ IDE in the C world?
Hi Dude,
You told without “C” we can’t imagine anything then why we are use this much of programming languages Perl,Python,Bash,JAVA ..etc.
Can you explain what are the difference between “C” these type languages(Perl,Python .etc) and clearly tell me which one is best programming language.
Regards,
Raja
Raja,
The “best” language is usually very subjective.
Some languages are better suited to certain tasks, e.g. SQL for interacting with a relational database and Javascript for web browsers.
Try different languages and specialize in the one that YOU like the best. :)
Yup! Turboc (Another compiler for C) is not case sensitive, however gcc is. Sorry for inconvenience
Turbo C is not case sensitive? I don’t believe that’s correct.
Older versions of the C standard permit (but do not require) external identifiers to be case-insensitive, but C in general has always been case sensitive, and I’m fairly sure Turbo C implemented that correctly.
And please *please* indent your code.
Please indent your code :)
“Note: C is not case sensitive, programming language.”
C IS a case sensitive programming language.
i.e. sprintf != SPRINTF
…”Note: C is not case sensitive, programming language. ” …
Uh ?
Maybe the ‘C/c” letter to name the language – but C-syntax constructs, language – IS – case sensitive …
where is the indentation? I presume this just an html formatting matter…