Learn C (Introduction and Tutorials To C Programming)
Learn C (Introduction and Tutorials To C Programming)
TUTORIAL EXAMPLES
Learn C Programming
C is a powerful general-purpose programming language. It is fast, portable and available in all platforms.
If you are new to programming, C is a good choice to start your programming journey.
This is a comprehensive guide on how to get started in C programming language, why you should learn it and
how you can learn it.
TABLE OF CONTENTS
-- C Tutorials
-- What is C Programming?
-- Reasons to Learn C
-- Recommended Books
-- Things to Remember
https://www.programiz.com/c-programming 1/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
TUTORIAL EXAMPLES
$20 price drop. Gator
Monitor Stands Frameworks GFW-SPK-SM50
Studio Monitor Stand (pair).
$99.99 Free shipping.
Before getting started with C programming, lets get familiarized with the language rst.
C is a general-purpose programming language used for wide range of applications from Operating systems like
Windows and iOS to software that is used for creating 3D movies.
C programming is highly e cient. That’s the main reason why it’s very popular despite being more than 40 years
old.
Standard C programs are portable. The source code written in one system works in another operating system
without any change.
As mentioned, it’s a good language to start learning programming. If you know C programming, you will not just
understand how your program works, but will also be able to create a mental picture on how a computer
works.
History of C programming
TUTORIAL EXAMPLES
Should you learn C programming?
If only it were possible to answer this question with a simple “yes” or “no”. Unfortunately, it’s not an easy
question to answer and varies from person to person.
Personally speaking, I love C programming. It is a good language to start your programming journey if you are a
newbie. Even if you are an experienced programmer, I recommend you to learn it at some point; it will certainly
help.
If you know C, you will not only know how your program works but, you will be able to create a
mental model on how a computer works (including memory management and allocation). You will learn
to appreciate the freedom that C provides unlike Python and Java.
https://www.programiz.com/c-programming 3/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
Understanding C allows you to write programs that you never thought were possible before (or at the
TUTORIAL EXAMPLES
very least, you will have a broader understanding of computer architecture and programming as a
whole).
Almost all high-level programming languages like Java, Python, JavaScript etc. can interface with C
programming. Also, it’s a good language to express common ideas in programming. Doesn’t matter if
the person you are talking with doesn’t know C, you can still convey your idea in a way they can
understand.
At rst, you may overlook the fact that C is an important language. If you need to develop a mobile
app, you need Java (for Android), Swift and Objective C (for iOS). And there are dozens of languages
like C#, PHP, ASP.net, Ruby, Python for building web application. Then, where is C programming?
Python is used for making wide range for applications. And, C is used for making Python. If you want
to contribute to Python, you need to know C programming to work on Python interpreter that impacts
millions of Python programmers. This is just one example. A large number of softwares that you use
today is powered by C.
Some of the larger open source projects where C programming is used are Linux Kernel, Python
Interpreter, SQLite Database.
Another language that’s commonly used for large open source project is C++. If you know C and C++,
you can contribute to large open source projects that impacts hundreds of millions of people.
https://www.programiz.com/c-programming 4/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
To be honest, this statement may not be true all the time. However, knowing how computer works
TUTORIAL EXAMPLES
and manage memory gives you insight on how to write e cient code in other programming languages.
A lot of popular programming languages are based on C (and C++, considered superset of C
programming with OOP features). If you know C, you will get a head start learning C++.
Languages like C# and Java are related to C and C++. Also, the syntax of JavaScript and PHP is similar
to C.
If you know C and C++ programming, you will not have any problem switching to another language.
If you are busy and don’t want to invest time on something that doesn’t have direct e ect on your day-to-day
work, C programming is not for you.
Also, if you are a newbie and want to start learning programming with an easier language (C is not the easiest
of language to learn), you can start with Python.
For many, C programming is the best language to start learning programming. However, if you want to start
with an easier language which is clean and easier to grasp, go for Python.
https://www.programiz.com/c-programming 5/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
Don’t leave your current project immediately (I know you won’t) to learn C. You can learn it when you have free
time and want to expand your programming skills.
I believe, it’s not necessary to learn C immediately. However, you should learn C eventually.
There are numerous compilers and text editors you can use to run C programming. These compilers and text
editors may di er from system to system.
You will nd the easiest way to run C programming on your computer (Windows, Mac OS X or Linux) in this
section.
https://www.programiz.com/c-programming 6/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
To make this procedure even easier, follow this step by step guide.
TUTORIAL EXAMPLES
1 Go to the binary release download page of Code:Blocks o cial site.
2 Under Windows XP / Vista / 7 / 8.x / 10 section, click the link with mingw-setup (highlighted row)
either from Sourceforge.net or FossHub.
3 Open the Code::Blocks Setup le and follow the instructions (Next > I agree > Next > Install); you
don’t need to change anything. This installs the Code::Blocks with gnu gcc compiler, which is the best
compiler to start with for beginners.
https://www.programiz.com/c-programming 7/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
4 Now, open Code::Blocks and go to File > New > Empty le (Shortcut: Ctrl + Shift + N)
TUTORIAL EXAMPLES
5 Write the C code and save the le with .c extension. To save the le, go to File > Save (Shortcut: Ctrl +
S).
https://www.programiz.com/c-programming 8/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
Important: The lename should end with a .c extension, like: hello.c, your-program-name.c
TUTORIAL EXAMPLES
6 To run the program, go to Build > Build and Run (Shortcut: F9). This will build the executable le and
run it.
If your program doesn’t run and if you see error message "can't nd compiler executable in your search
path(GNU GCC compiler)", go to Settings > Compiler > Toolchain executables and click Auto-detect. This should
solve the issue in most cases.
https://www.programiz.com/c-programming 9/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
This program is often used to introduce programming language to a beginner. So, let’s get started.
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
C programming is small and cannot do much by itself. You need to use libraries that are necessary to run the
program. The stdio.h is a header le and C compiler knows the location of that le. To use the le, you need
to include it in your program using #include preprocessor.
https://www.programiz.com/c-programming 10/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
In this program, we have used printf() function which displays the text inside the quotation mark. Since
TUTORIAL EXAMPLES
printf() is de ned in stdio.h , you need to include stdio.h .
In C programming, the code execution begins from the start of main() function (doesn’t matter if main() isn’t
located at the beginning).
The code inside the curly braces { } is the body of main() function. The main() function is mandatory in every C
program.
int main() {
}
The printf() is a library function that sends formatted output to the screen (displays the string inside the
quotation mark). Notice the semicolon at the end of the statement.
Remember, you need to include stdio.h le in your program for this to work.
The return statement return 0; inside the main() function ends the program. This statement isn’t mandatory.
However, it’s considered good programming practice to use it.
https://www.programiz.com/c-programming 11/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
Key notesEXAMPLES
to take away
TUTORIAL
All C program starts from the main() function and it’s mandatory.
You can use the required header le that’s necessary in the program. For example: To use sqrt() function
to calculate square root and pow() function to nd power of a number, you need to include math.h header
le in your program.
C is case-sensitive; the use of uppercase letter and lowercase letter have di erent meanings.
The C program ends when the program encounters the return statement inside the main() function.
However, return statement inside the main function is not mandatory.
The statement in a C program ends with a semicolon.
The tutorials are designed for beginners who do not have any prior knowledge of C programming (or, any other
programming languages). Each tutorial is written in depth with examples and detailed explanation.
Granted, reading a 600 page long programming book takes a lot of time and patience. But, you will get the big
picture of programming concepts in the book which you may not nd elsewhere.
https://www.programiz.com/c-programming 12/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
This book is clear and comprehensive. Also, the Q&A section at the end of each chapter makes this book a must
have for beginners.
Fact: You cannot learn C programming in a day. You might have di culty grasping the important concepts if you
try to learn C programming faster.
If you just learn the syntax and dive in, your C code may work but you’ll not end up learning C programming
the right way.,
If you want to learn a new feature of C programming, try to write code related to that feature. If you can’t, copy
code from Programiz and run it in your system. Then, try to understand it. Once you understand it, modify the
code, make it di erent and run it again.
https://www.programiz.com/c-programming 14/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
When you have bugs in your program, rather than scratching your head to nd the bug, you can use debugger
TUTORIAL EXAMPLES
to stop program at any point and nd the value of variables to detect the bug.
Knowing how to use a debugger is an important skill that every programmer should learn.
To answer this question, you should have a good knowledge of when to use an array and when to use a
structure.
Suppose, you are switching to C from a di erent language, let’s say C#. You do not want to write C# style code
with C syntax in your C program.
Join C communities
Once you get the hang of writing simple C programs, join online communities and forums. You can help other
programmers where you can and ask for help when you are stuck.
Private Google forum for C Programmers - It’s a gem for C programming beginners.
Codechef - Practice questions, challenges and a large community of programmers
StackOver ow - Most Popular programming Q&A site on the web
https://www.programiz.com/c-programming 15/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
Good programming practice are the informal rules which can improve quality and decrease development time of
TUTORIAL
the software.
EXAMPLES
Some of the programming practices mentioned here are valid in all programming languages whereas some are
valid only for C programming.
The number of spaces you use in the program doesn’t matter in C. However, that doesn’t mean you should use
di erent number of spaces at di erent places. Also, use proper indentation so that the code is easier to
understand.
int count;
float squareRoot = 10.0;
printf(“Square root = %f”, squareRoot);
The goal here is to write code that your fellow programmers can understand.
Give a proper name to variables and functions and be consistent with it.
https://www.programiz.com/c-programming 16/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
TUTORIAL
int a, b; EXAMPLES
Here, a and b are two variables and I have no idea what they do. Instead you can choose name like:
Both conventions: using _ to separate words and using capital letter after rst word is popular. However, don’t
use both in one program; choose one and be consistent with it.
You can use comments in your program to explain what you are trying to achieve in your program. This helps
your fellow programmer to understand the code.
// My first C program
#include <stdio.h>
int main()
{
printf("Hello, World!\n"); // displays Hello, World! on the screen
https://www.programiz.com/c-programming 17/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
return 0;
}
TUTORIAL EXAMPLES
“Commenting your code is like cleaning your bathroom - you never want to do it, but it really does
create a more pleasant experience for you and your guests.”
— Ryan Campbell
If you are a beginner, it’s a good language to start learning programming. And, if you are a professional
programmer with a tight schedule, learn it at your leisure; it will certainly help your brush up on programming
basics.
C Tutorial
INTRODUCTION
C Data Types
C Input/Output
C Operators
https://www.programiz.com/c-programming 18/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
TUTORIAL BasicEXAMPLES
Examples
FLOW CONTROL
if...else Statement
C for Loop
C while Loop
switch Statement
Decision Examples
FUNCTIONS
Functions Introduction
User-defined Function
Function Types
Recursion in C
Variable Scope
https://www.programiz.com/c-programming 19/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
ARRAYS
C Arrays Introduction
Multidimensional Array
Strings in C
String Functions
Array Examples
C POINTERS
C Pointers
Memory Management
Pointer Examples
https://www.programiz.com/c-programming 20/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
C Unions
Structure Examples
Files Handling
ADDITIONAL RESOURCES
C Examples
C Library Function
Subscribe
https://www.programiz.com/c-programming 21/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)
Subscribe
ABOUT
CONTACT
ADVERTISE
https://www.programiz.com/c-programming 22/22