100% found this document useful (1 vote)
74 views

Learn C (Introduction and Tutorials To C Programming)

This document provides an introduction and overview of learning C programming. It discusses that C is a powerful general-purpose language that is fast, portable, and available on all platforms. It recommends C as a good first programming language to learn as it helps understand how programs and computers work. The document provides a table of contents on C tutorials, the basics of C, reasons to learn C, writing your first C program, recommended books, and things to remember when learning C. It also discusses how to compile and run C programs on different operating systems.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
74 views

Learn C (Introduction and Tutorials To C Programming)

This document provides an introduction and overview of learning C programming. It discusses that C is a powerful general-purpose language that is fast, portable, and available on all platforms. It recommends C as a good first programming language to learn as it helps understand how programs and computers work. The document provides a table of contents on C tutorials, the basics of C, reasons to learn C, writing your first C program, recommended books, and things to remember when learning C. It also discusses how to compile and run C programs on different operating systems.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

4/27/2018 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

-- Your First C Program

-- 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.

What is C (Programming Language)? - The Basics

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.

More information on C Language.

History of C programming

Features of C Programming Language


https://www.programiz.com/c-programming 2/22
4/27/2018 Learn C (Introduction and Tutorials to 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.

$20 price drop. Gator


Monitor Stands Frameworks GFW-SPK-SM50
Studio Monitor Stand (pair).
$99.99 Free shipping.

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.

What will you gain if you learn C?


If you don’t know C, you don’t know what you are doing as a programmer. Sure, your application works ne and
all. But, if you can’t say why while (*s++ = *p++); copies a string, you’re programming on a superstition. ( Joel
Spolsky’s words, not mine ).

1 You will understand how a computer works.

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).

2 C is the lingua franca of programming.

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.

3 Opportunity to work on open source projects that impact millions of people.

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.

4 You will write better programs.

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.

5 You will nd it much easier to learn 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.

Reasons not to learn C programming


You can create awesome softwares without knowing C programming at all. Je Atwood, one of the creators of
Stackover ow.com, apparently doesn’t know C and Stack Over ow is a really good web application.

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.

Verdict on whether to learn C programming or not


For newbie:

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)

For experienced programmers:


TUTORIAL EXAMPLES 
It’s not absolutely essential but there are perks of learning 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.

Compile and run C programming on your OS

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.

Run C program Online

Run C Programming in Mac OS X

Run C programming on Linux

Run C Programming in Windows (XP, 7, 8 and 10)


To run C Programming in Windows, download a software called Code::Blocks. Then, write C code, save the le
with .c extension and execute the code.

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.

The fun begins: Your rst C program

You will learn to write a “Hello, World!” program in this section.

https://www.programiz.com/c-programming 9/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)

Why “Hello, World!” program?


TUTORIAL EXAMPLES 
“Hello, World!” is a simple program that displays “Hello, World!” on the screen. Since, it’s a very simple program,
it is used to illustrate the basic syntax of any programming language.

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;
}

How “Hello, World!” program works?


Include stdio.h header le in your program.

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.

Why do you need stdio.h le in this program?

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 . 

The main() function

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() {
}

This program doesn’t do anything but, it’s a valid C program.

The printf() function

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.

In our program, it displays Hello, World! on the screen.

Remember, you need to include stdio.h le in your program for this to work.

The return statement

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.

Teach Yourself to Code in C

Learn C from Programiz


Programiz o ers dozens of tutorials and examples to help you learn C programming from scratch.

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.

Recommended Books in C Programming


If you are serious about learning programming (any programming language including C), you should get yourself
a good book.

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)

Here are 3 books we personally recommend.


TUTORIAL EXAMPLES 

The C Programming Language (2nd Edition)


This book provides the complete guide to ANSI standard C language.

Most importantly, it’s co-written by Dennis M. Ritchie, creator of C programming language.

Get this book

Get book (India)

C Programming: A Modern Approach (2nd Edition)


Personally I believe, this is the best book for beginners.

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.

Get this book

Get book (India)

C Pocket Reference (1st Edition)


Don’t want to search pages and pages to look for a small information? Get this book.

As suggested by the name, it’s a small book for reference.


https://www.programiz.com/c-programming 13/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)

Get this book


TUTORIAL EXAMPLES 
Get book (India)

Learn C programming, the right way

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.,

Don’t just look at the example code, run it in your system


Programiz has dozens of examples that will help you understand C programming. However, if you are reading it
like a novel without running it in your system, you are doing it wrong.

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.

Learn to use a Debugging tool


A debugging tool or debugger is a software (that’s already available in IDE) which allows programmers to stop a
program at any point and helps to detect and correct errors.

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.

Learn the feature the way it is intended


Imagine a situation: It’s possible to solve a problem with an array. Also, you can solve the same problem with a
structure. Technically both are correct, which method will you use?

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.

Communities Programiz recommends you to join:

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

Always follow good programming practice

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.

Be consistent with the formatting.

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.

Use one statement per line.

What’s wrong with the following code?

int count; float squareRoot = 10.0; printf(“Square root = %f”, squareRoot);

Actually, the code is perfectly valid. But, wouldn’t this be better:

int count;
float squareRoot = 10.0;
printf(“Square root = %f”, squareRoot);

The goal here is to write code that your fellow programmers can understand.

Naming convention and Consistency!

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:

int counter, power;

Also, follow a convention while naming. For example:

int base_number, powerNumber;

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.

Start Habit of Using Comments

Comments are part of code that compiler ignores.

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.

You can use comments in C programming by using //. For example:

// 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

We at Programiz think C is a terri c language to learn.

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

Keywords & Identifier

Variables & Constants

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

break and continue

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)

TUTORIAL Function Examples


EXAMPLES 

ARRAYS

C Arrays Introduction

Multidimensional Array

Arrays & Functions

Strings in C

String Functions

Array Examples

C POINTERS

C Pointers

Pointers & Arrays

Pointers & Functions

Memory Management

Pointer Examples

https://www.programiz.com/c-programming 20/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)

STRUCTURE & FILE


TUTORIAL EXAMPLES 
C Structure

Structure & Pointers

Structure & Functions

C Unions

Structure Examples

Files Handling

ADDITIONAL RESOURCES

C Examples

C Library Function

Get latest updates, articles and tutorials on C programming.

Enter Your Email

Subscribe

https://www.programiz.com/c-programming 21/22
4/27/2018 Learn C (Introduction and Tutorials to C Programming)

Get Latest Updates on Programiz


TUTORIAL EXAMPLES 
Enter Your Email

Subscribe

ABOUT
CONTACT
ADVERTISE

Copyright © by Programiz | All rights reserved | Privacy Policy | Terms of Use

https://www.programiz.com/c-programming 22/22

You might also like