Modern C For Absolute Beginners: A Friendly Introduction To The C Programming Language 2nd Edition Slobodan Dmitrović Instant Download
Modern C For Absolute Beginners: A Friendly Introduction To The C Programming Language 2nd Edition Slobodan Dmitrović Instant Download
https://ebookmass.com/product/modern-c-for-absolute-beginners-a-
friendly-introduction-to-the-c-programming-language-2nd-edition-
slobodan-dmitrovic/
https://ebookmass.com/product/modern-c-for-absolute-beginners-2nd-
edition-slobodan-dmitrovic/
https://ebookmass.com/product/modern-c-for-absolute-beginners-second-
edition-solbodan-dmitrovic/
https://ebookmass.com/product/programming-for-absolute-beginners-
using-the-javascript-programming-language-1st-edition-jonathan-
bartlett/
C Programming Language: C PROGRAMMING LANG _p2 2nd
Edition, (Ebook PDF)
https://ebookmass.com/product/c-programming-language-c-programming-
lang-_p2-2nd-edition-ebook-pdf/
https://ebookmass.com/product/c-programming-absolute-beginners-
guide-3rd-edition-perry/
https://ebookmass.com/product/c-programming-for-beginners-by-sett-
john-hafeez-abdulmutolib/
https://ebookmass.com/product/c-programming-for-dummies-2nd-edition-
dan-gookin/
Slobodan Dmitrović
Modern C for Absolute Beginners: A Friendly Introduction to the C Programming
Language, Second Edition
Slobodan Dmitrović
Belgrade, Serbia
Acknowledgments��������������������������������������������������������������������������������������������������xix
Introduction������������������������������������������������������������������������������������������������������������xxi
v
Table of Contents
Chapter 4: Exercises����������������������������������������������������������������������������������������������� 31
4.1 Hello World with Comments�������������������������������������������������������������������������������������������������� 31
4.1.1 Declaration������������������������������������������������������������������������������������������������������������������� 32
4.1.2 Definition���������������������������������������������������������������������������������������������������������������������� 32
4.1.3 Outputting Values��������������������������������������������������������������������������������������������������������� 32
Chapter 5: Operators���������������������������������������������������������������������������������������������� 35
5.1 Introduction��������������������������������������������������������������������������������������������������������������������������� 35
5.2 Arithmetic Operators������������������������������������������������������������������������������������������������������������� 35
5.3 Assignment Operator������������������������������������������������������������������������������������������������������������ 36
5.4 Compound Assignment Operators���������������������������������������������������������������������������������������� 38
5.5 Relational Operators������������������������������������������������������������������������������������������������������������� 39
5.6 Equality Operators����������������������������������������������������������������������������������������������������������������� 40
5.7 Logical Operators������������������������������������������������������������������������������������������������������������������ 41
5.8 Increment and Decrement Operators������������������������������������������������������������������������������������ 42
5.9 Operator Precedence������������������������������������������������������������������������������������������������������������ 43
Chapter 6: Expressions������������������������������������������������������������������������������������������� 45
6.1 Initialization��������������������������������������������������������������������������������������������������������������������������� 45
6.2 Type Conversion�������������������������������������������������������������������������������������������������������������������� 46
Chapter 7: Statements�������������������������������������������������������������������������������������������� 49
7.1 Introduction��������������������������������������������������������������������������������������������������������������������������� 49
7.2 Selection Statements������������������������������������������������������������������������������������������������������������ 51
7.2.1 if����������������������������������������������������������������������������������������������������������������������������������� 51
7.2.2 if-else��������������������������������������������������������������������������������������������������������������������������� 54
7.2.3 switch��������������������������������������������������������������������������������������������������������������������������� 56
vi
Table of Contents
Chapter 8: Exercises����������������������������������������������������������������������������������������������� 65
8.1 Arithmetic Operations����������������������������������������������������������������������������������������������������������� 65
8.2 Integral Division�������������������������������������������������������������������������������������������������������������������� 65
8.3 Floating-Point Division and Casting�������������������������������������������������������������������������������������� 66
8.4 Equality Operator������������������������������������������������������������������������������������������������������������������ 66
8.5 Relational and Logical Operators������������������������������������������������������������������������������������������ 67
8.6 The switch Statement����������������������������������������������������������������������������������������������������������� 68
8.7 Iteration Statements������������������������������������������������������������������������������������������������������������� 68
Chapter 9: Arrays���������������������������������������������������������������������������������������������������� 71
9.1 Declaration���������������������������������������������������������������������������������������������������������������������������� 71
9.2 Subscript Operator���������������������������������������������������������������������������������������������������������������� 72
9.3 Array Initialization����������������������������������������������������������������������������������������������������������������� 74
9.4 Character Arrays������������������������������������������������������������������������������������������������������������������� 76
9.5 Multidimensional Arrays������������������������������������������������������������������������������������������������������� 77
9.6 Array Size and Count������������������������������������������������������������������������������������������������������������� 78
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
x
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Table of Contents
xi
Table of Contents
xii
Table of Contents
Chapter 39: Do Not Free the Allocated Memory Twice����������������������������������������� 297
Chapter 42: Cast a Pointer to void* When Printing Through printf����������������������� 303
xiii
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 347
xiv
About the Author
Slobodan Dmitrović is a software consultant, trainer, and
author of several programming books. He is a professional
R&D software developer with two decades of experience in
the industry. Slobodan provides C and C++ training courses
to corporate clients and academic institutions. Contact
Slobodan at linkedin.com/in/slobodan-dmitrovic.
xv
About the Technical Reviewer
German Gonzalez-Morris is a polyglot software architect/
engineer with 20+ years in the field, with knowledge in Java,
Spring Boot, C/C++, Julia, Python, Haskell, and JavaScript,
among others. He works with cloud (architecture),
web-distributed applications, and microservices. German
loves math puzzles (including reading Knuth, proud of
solving some of Don’s puzzles), swimming, and table tennis.
Also, he has reviewed several books, including an application
container book (WebLogic) and some on languages (C, Java,
Spring, Python, Haskell, TypeScript, WebAssembly, Math for
coders, regexp, Julia, data structures and algorithms). You
can see details in his blog https://devwebcl.blogspot.com/
or X/Twitter account: @devwebcl.
xvii
Acknowledgments
I want to thank the readers, friends, and peers who have supported me in writing the
second edition of this book.
I am indebted to Peter Dunne, Glenn Dufke, Bruce McGee, Tim Crouse, Jens Fudge,
Rainer Grimm, and Rob Machin for all their work, help, and support.
I am grateful to the outstanding professionals at Apress who have supported me
throughout the writing process.
I am thankful to all the amazing software developers, architects, and entrepreneurs I
met and collaborated with.
xix
Introduction
Dear reader, congratulations on choosing to learn the C programming language, and
thank you for picking up this book. My name is Slobodan Dmitrović, and I will try to
introduce you to the wonderful world of C programming to the best of my abilities.
This book is divided into five parts. In Part 1, we cover the C language basics. Part 2
explains the C standard library, and Part 3 introduces us to modern C standards. Part 4
explains the dos and don’ts in modern C. The final part consists of the Appendices. Let
us get started!
xxi
PART I
The C Programming
Language
CHAPTER 1
Introduction
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 or library. For the most part, we say we
compile the program and assume the compilation process results in an executable file we
can run. At the time of writing, some of the more popular C compilers are
3
© Slobodan Dmitrović 2024
S. Dmitrović, Modern C for Absolute Beginners, https://doi.org/10.1007/979-8-8688-0224-9_1
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Exploring the Variety of Random
Documents with Different Content
venäläisten voimakkaita rynnäkköjä, mutta olivat nyt sekä perin
uupuneita että ilman ampumavaroja. —
III.
Toinen peräytymisretki.
1.
Hänen tunteensa eivät siis olleet iloisia, kun hän illalla lokakuun 28
päivänä verkkaan käyskeli edestakasin äärimmäisellä vallilla, jossa
työt olivat toistaiseksi lopetettu. Eräällä vallin kulmakkeella seisoi
joukko upseereja, keskustellen matalalla äänellä, etteivät olisi
häirinneet ajatuksiinsa vaipunutta päällikköä. Joukossa oli myöskin
Valter Jernfält.
Taistelun päätyttyä oli hän Sandelsin luvalla lähettänyt Olgan
Niemeen, koska tämä ei enää voinut olla turvattuna leirissä niiden
uusien ja ehkä vieläkin verisempien taistelujen tähden, joita oli
tulossa.
— En. —
2.
— No, Jumalan kiitos, että olet täällä jälleen! Sanohan nyt kaikista
ensiksi, miten Valter jaksaa, sitte saat kertoa omat kuulumisesi. —
*****
— Päivettynyt syksyllä! —
— Näen. —
— Sitä poikaa! —
4.
— Piiritetään! —
5.
Yksi näistä oli Patrik Jernfält ja kaksi muuta Valter sekä hänen
nuori puolisonsa Olga, joista edellinen oli Savon jääkäripataljoonan
kapteenin univormussa.
— Oli se sentään aika hyvä onni, että niin hyvissä ajoin myin
Niemen, jota sitä paitsi vihollinen ryösti ja poltti kohta teidän
lähdettyänne Pulkkilasta, — sanoi Patrik Jernfält. — Muuten olisin
minä jäänyt puille paljaille. —
— Oi, miten kaunista täällä on, — virkkoi Olga, kun olivat tulleet
Pohjoissillalle. — Tämmöistä ei monessa pääkaupungissa liene
nähtävänä. —
— Kapteeni Jernfält! —
Updated editions will replace the previous one—the old editions will
be renamed.
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.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• 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.
ebookmasss.com