Download ebooks file Modern C for Absolute Beginners A Friendly Introduction to the C Programming Language Dmitrović Slobodan all chapters
Download ebooks file Modern C for Absolute Beginners A Friendly Introduction to the C Programming Language Dmitrović Slobodan all chapters
com
https://textbookfull.com/product/modern-c-for-absolute-
beginners-a-friendly-introduction-to-the-c-programming-
language-dmitrovic-slobodan/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/modern-c-for-absolute-beginners-a-
friendly-introduction-to-the-c-programming-language-dmitrovic-
slobodan/
textboxfull.com
https://textbookfull.com/product/modern-c-for-absolute-beginners-1st-
edition-slobodan-dmitrovic/
textboxfull.com
Modern C++ for Absolute Beginners 1st Edition Slobodan
Dmitrovi■ [Dmitrovi■
https://textbookfull.com/product/modern-c-for-absolute-beginners-1st-
edition-slobodan-dmitrovic-dmitrovic/
textboxfull.com
https://textbookfull.com/product/c-programming-for-absolute-beginners-
radek-vystavel/
textboxfull.com
https://textbookfull.com/product/modern-c-for-absolute-beginners-
second-edition-solbodan-dmitrovic/
textboxfull.com
https://textbookfull.com/product/introduction-to-google-analytics-a-
guide-for-absolute-beginners-todd-kelsey/
textboxfull.com
https://textbookfull.com/product/introduction-to-search-engine-
optimization-a-guide-for-absolute-beginners-todd-kelsey/
textboxfull.com
Slobodan Dmitrović
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
1. Introduction
Slobodan Dmitrović 1
(1) Belgrade, Serbia
1.1 What Is C?
C is a programming language, a general-purpose, procedural, compiled
programming language. C language was created by Dennis Ritchie in
the late 1960s and early 1970s. The C program is a collection of C
source code spread across one or more source and header files. Source
files by convention have the .c extension, and header files have the .h
extension. Source and header files are plain text files that contain some
C code.
1.3 C Compilers
To compile and run a C program, we need a C compiler. A compiler
compiles a C program and turns the source code into an object file. The
linker then links the object files together and produces an executable
file or a library, depending on our intention. For the most part, we say
we compile the program and assume the compilation process results in
an executable file that we can run. At the time of writing, some of the
more popular C compilers are:
gcc – as part of the GCC toolchain
Clang – as part of the LLVM toolchain
Visual C/C++ compiler – as part of the Visual Studio IDE
MinGW – a Windows port of the GCC
1.3.1.1 On Linux
To install a GCC compiler on Linux , open a terminal window and type:
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
}
Let us save the file as a source.c. To compile this program using GCC,
we type:
gcc source.c
./a.out
Note For now, let us take the source code inside the source.c file for
granted. The example is for demonstration purposes. We will get into
detailed code explanation and analysis in later chapters.
clang source.c
Same as before, the compiler compiles the source file and produces
an executable file with the default name of a.out. To run this file, we
type:
./a.out
./myexe
If using Clang:
1.3.1.2 On Windows
On Windows , we can install Visual Studio. Choose the Create a new
project option, make sure the C++ option is selected, choose Empty
Project, and click Next. Modify the project and solution names or leave
the default values, and click Create. We have now created an empty
Visual Studio project. In the Solution Explorer window, right-click on a
project name and choose Add – New Item…. Ensure the Visual C++ tab is
selected, click on the C++ File (.cpp) option, modify the file name to
source.c, and click Add. We can use a different file name, but the
extension should be .c. Double-click on the source.c file, and paste our
previous Hello World source code into it. Press F5 to run the program.
To compile for the C11 standard, use the /std:c11 compiler switch.
To compile for the C17 standard, use the /std:c17 compiler switch.
Alternatively, install the MinGW (Minimalist GNU for Windows) and
use the compiler in a console window, the same way we would on
Linux.
So far, we have learned how to set up the programming
environments on Linux and Windows and compile and run our C
programs. We are now ready to start with the C theory and examples.
1.4 C Standards
The C programming language is a standardized language. There were
different C standards throughout history. The first notable standard
was the ANSI C, and now it is the ISO standard known as the
ISO/IEC:9989 standard. Some of the C standards throughout the years:
ANSI C Standard (referred to as ANSI C and C89)
C90 (official name: ISO/IEC 9899:1990; it is the ANSI C Standard
adopted by ISO; the C89 and C90 are the same things)
C99 (ISO/IEC 9899:1999)
C11 (ISO/IEC 9899:2011)
C17 (ISO/IEC 9899:2018)
The upcoming standard informally named C2x
Each of the standards introduces new features and changes to the
language and the standard library. Everything starting with C11 is often
referred to as the modern C. And modern C is what we will be teaching
in this book. Let us get started!
© Slobodan Dmitrović 2021
S. Dmitrović, Modern C for Absolute Beginners
https://doi.org/10.1007/978-1-4842-6643-4_2
This section describes the main program entry point, how to work with
comments, and how to write a simple “Hello World” program.
int main(void) {}
The function main is of type int, which stands for integer, followed
by the reserved name main, followed by an empty list of parameters
inside the parentheses (void). The name void inside the
parentheses means the function accepts no parameters. Following is
the function body marked with braces {}. The opening brace { marks
the beginning of a code block, and the closing brace } marks the end of
the code block. We write our C code inside the code block marked by
these braces. The code we write there executes when we start our
executable file.
For readability reasons, we can put braces on new lines:
int main(void)
{
}
We can keep the opening brace on the same line with the main
function definition and have the ending brace on a new line:
int main(void) {
int main(void)
{
return 0;
}
int main(void)
{
}
We often see the use of the following, also valid main signature:
int main()
{
return 0;
}
int main(void)
{
2.2 Comments
We can have comments in our C program. A comment is a text that is
useful to us but is ignored by the compiler. Comments are used to
document the source code, serve as notes, or comment-out the part of
the source code.
A C-style comment starts with /* characters and ends with */
characters. The comment text is placed between these characters.
Example:
int main(void)
{
/* This is a comment in C */
}
The comment can also be a multiline comment:
int main(void)
{
/* This is a
multi-line comment in C */
}
int main(void)
{
// This is a comment
}
int main(void)
{
// This is a comment
// This is another comment
}
#include <stdio.h>
Random documents with unrelated
content Scribd suggests to you:
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law in
the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms of
this agreement by keeping this work in the same format with its
attached full Project Gutenberg™ License when you share it without
charge with others.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the terms
of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com