0% found this document useful (0 votes)
42 views78 pages

Introduction To Computer Science For Beginners

This document serves as a comprehensive guide for beginners in computer science, emphasizing the importance of understanding fundamental concepts and techniques. It recommends the CS50 online course by Harvard University as a starting point and suggests using a guidebook or notebook to enhance learning. The guidebook outlines key topics covered in the course, including binary notation, ASCII, and programming basics.

Uploaded by

boekarest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views78 pages

Introduction To Computer Science For Beginners

This document serves as a comprehensive guide for beginners in computer science, emphasizing the importance of understanding fundamental concepts and techniques. It recommends the CS50 online course by Harvard University as a starting point and suggests using a guidebook or notebook to enhance learning. The guidebook outlines key topics covered in the course, including binary notation, ASCII, and programming basics.

Uploaded by

boekarest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Introduction to Computer

Science for Beginners: A


Comprehensive Guide to
Computer Science
Fundamentals Part 01
INTRODUCTION
Computer science is a rapidly-evolving field that plays a crucial role in our daily lives.
From the devices we use to communicate and access information, to the systems
that power the internet and the world's financial markets, computer science touches
nearly every aspect of modern society.
As a beginner looking to learn more about computer science, you may feel
overwhelmed by the sheer breadth and depth of the field. Where do you start? What
concepts and techniques are most important? How can you keep up with the
constant stream of new technologies and developments?
One great way to get started is by taking an online course like CS50, offered by
Harvard University. With millions of students around the world, this course has
helped to demystify the world of computer science for countless learners. Through a
combination of video lectures, readings, and hands-on exercises, CS50 covers the
fundamental concepts and techniques that form the foundation of computer science.

Whether you are a complete novice or an experienced programmer, CS50 is a great


way to learn more about computer science. And to help you make the most of the
course, you may find it helpful to use a guidebook or notebook to take notes, clarify
concepts, and ask yourself questions as you progress.

So don't be intimidated by the vastness of computer science! With the help of


resources like CS50 and a guidebook/notebook to accompany the course, you can
start building a strong foundation in this exciting and rewarding field.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 1
01
COURCE: SC50 Video lecture by DAVID J. MALAN

https://www.youtube.com/watch?v=8mAITcNt710

What do you get in this guidebook?


In this guidebook/notebook, you will find important notes, examples, and detailed
explanations about the key concepts covered in the CS50 video lectures. These
notes and examples will help you to better understand and remember the material,
With this guidebook/notebook as a companion to the CS50 video lectures, you will
have a valuable resource to help you learn and retain the key concepts of computer
science. Whether you are a beginner seeking to learn the basics of programming or
an experienced developer looking to deepen your understanding of the field, this
guidebook/notebook will be an invaluable tool on your learning journey.

GUIDEBOOK OUTLINE

Week 0 Scratch
SL NO. SUBJECTS TIME STAMP PAGE NO.

1 Unary notation [00:07:10] 04

2 Binary & Decimal [00:07:36] 05

3 How Binary work 06

4 Formula 07

5 ASCII [00:17:12] 08

6 ASCII TABLE 1 08

7 ASCII TABLE 2 09

8 UNICODE [00:21:38] 13

9 RGB [00:26:10] 13

10 MIDI [00:31:24] 14

11 Psedo code [00:44:35] 14

12 Introduction to the Scratch [00:50:28] 17

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 2
01
programming language
13 Functions [00:58:24] 17

14 Variables 18

15 Boolean expressions 18

16 Conditionals 19

17 Loops, and events 19

Week 1 C [1:47:45]
SL NO. SUBJECTS TIME STAMP PAGE NO.

18 Correctness [1:50:00] 20

19 Design 21

20 Style 22

21 Conclusion 23

Using Visual Studio Code for coding


22 [01:53:48] 23
in C

23 Syntax highlighting in code editors 24

24 "Hello, World!" 26

Integrated Development
25 [1:53:38] 27
Environment

26 Command Line Interface (CLI) [02:00:20] 28

27 “./ “command [02:01:27] 29

28 Graphical User Interface (GUI) 29

29 Source Code & Matchin Code 30

30 Function [02:08:17] 31

31 Argument 32

32 String [02:09:26] 33

33 Side Effects 34

34 Return Value [02:10:45] 35

35 “=” Sign means [02:12:46] 36

36 \n Means [02:16:43] 38

37 <sdtio.h> Means [02:22:44] 39

38 <sc50.h> Means 40

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 3
01
39 %s Means [02:24:00] 42

40 printf means [02:25:00] 43

41 Syntax highlights 44

42 Header files [02:33:48] 45

43 How to navigate in CLI [02:38:09] 46

44 DATA Types in C [02:43:35] 48

45 CS50 library get functions [02:44;40] 52

46 Format specifiers [02:45:15] 53

47 Operators [02:45:50] 55

48 Variable and Syntactic sugar [02:46:15] 56

49 Make Calculator Step by Step [02:50:10] 57

50 Comment [02:55:20] 59

51 Constant [03:09:37] 60

52 OR operator (”||’’), [03:18:36] 61

53 AND operator (’’&&’’) 63

54 while loop [03:23:06] 64

55 Less than or equal to another (’’<=’’) [03:27:56] 66

56 for loop [03:28:58] [03:28:58] 68

57 Custom functions [03:31:58] 69

58 do-while loop [03:50:13] 71

59 Floating-point imprecision [04:01:19] 73

60 Truncation [04:02:41] 75

61 Type conversion [04:03:40] 76

62 Integer overflow 77

Week 0 Scratch
Unary notation [00:07:10]
Unary notation is a way of representing numbers using only a single digit or symbol.
In unary notation, the number of symbols used corresponds to the value of the
number being represented. For example, the number 4 can be represented in unary
notation as "||||".

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 4
01
Unary notation is not commonly used, as it is not very efficient. It can be difficult to
represent larger numbers in unary notation, as the number of symbols required
increases rapidly. However, it can be useful in certain contexts, such as when
working with very large numbers or in certain types of computer algorithms.

Binary & Decimal [00:07:36]


Computers use the binary numbering system to count and perform arithmetic
operations. In binary, there are only two digits: 0 and 1. These digits are known as
"bits," and they can be combined to represent different values or instructions.

To count in binary, the computer starts with a value of 0 and increments the value by
1 each time. When it reaches the maximum value that can be represented with a
given number of bits (for example, 111 in three-bit binary), the next increment causes
the value to roll over to the minimum value (in this case, 000) and an additional
"carry" bit is added to the left to represent the extra value. This is similar to how
carrying works in the decimal system.

For example, here's how the computer would count from 0 to 10 in binary:

Decimal Binary

0 0

1 1

2 10

3 11

4 100

5 101

6 110

7 111

8 1000

9 1001

10 1010

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 5
01
💠 NOTE

Binary is a numbering system that uses only two digits: 0 and 1.

These digits are called "bits," and they can be combined to represent
different values or instructions.

Computers use binary to communicate with hardware and perform


tasks.

Binary is the foundation of all modern computing, and it's used in


everything from programming and operating systems to data storage
and transmission.

Every time you use a computer, it's following a series of instructions


written in binary code.

How Binary work


In the binary numbering system, the number 1110 represents the decimal (base 10)
value of 14.
To understand why this is the case, you need to know how the place values of a
binary number work. Each place value in a binary number is double the value of the
place to its right. For example, the "ones" place has a value of 1, the "twos" place
has a value of 2, the "fours" place has a value of 4, and so on.
Here's how you can determine the decimal value of the binary number 1110:

1. Start from the rightmost digit and work your way left.

2. For each 1 that you encounter, add the value of the place to the running total.

So, for the binary number 1110, you would do the following:

1. Start with the rightmost digit, which is 0. Its place value is 1, so you don't add
anything to the running total.

2. The next digit is 1. Its place value is 2, so you add 2 to the running total (which is
currently 0).

3. The next digit is 1. Its place value is 4, so you add 4 to the running total (which is
currently 2).

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 6
01
4. The final digit is 1. Its place value is 8, so you add 8 to the running total (which is
currently 6).

After adding up all the place values for the 1s in the binary number, you get a total of
14. Therefore, the binary number 1110 represents the decimal value of 14.

Formula
To convert a binary number to its decimal (base 10) equivalent, you can use the
following formula:

decimal = (1 x bn) + (2 x bn-1) + (4 x bn-2) + ... + (2^n x b0)

Where:

decimal is the decimal value of the binary number

bn is the nth digit of the binary number, starting from the rightmost digit and
working left

n is the number of digits in the binary number

For example, to convert the binary number 1110 to decimal, you would use the
following formula:

decimal = (1 x 0) + (2 x 0) + (4 x 1) + (8 x 1)
=0+0+4+8
= 14
EXAMPLE

In the binary numbering system, the symbol for the number 11 is 1011.

To understand why this is the case, you need to know how the place values of a
binary number work. Each place value in a binary number is double the value of the
place to its right. For example, the "ones" place has a value of 1, the "twos" place
has a value of 2, the "fours" place has a value of 4, and so on.

In the case of the number 11, you would need to use four digits to represent it in
binary, since the largest place value is 8 (which is less than 11). The binary
representation of 11 would be "1011," which stands for:

1. 1 in the "eight" place (8)

2. 0 in the "fours" place (0)

3. 1 in the "twos" place (2)

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 7
01
4. 1 in the "ones" place (1)

Adding up all these values gives you a total of 11, which is why the binary number
"1011" represents the decimal value of 11.

ASCII [00:17:12]
ASCII (pronounced "ask-ee") stands for American Standard Code for Information
Interchange. It is a standardized code used to represent characters (letters,
numbers, symbols, etc.) in computers and other devices.
Each character in the ASCII table is represented by a unique number between 0 and
127. For example, the letter "A" is represented by the number 65, the letter "B" is
represented by the number 66, and so on. ASCII codes are usually represented
using the binary numbering system since computers understand and process data in
the form of binary digits (bits).
ASCII is used to represent characters in many different contexts, including text files,
email messages, and web pages. It is a widely used and widely supported standard,
which makes it easy to exchange text and other data between different devices and
systems.

ASCII TABLE 1
Dec Bin Char

0 00010000 NUL (null)

1 00010001 SOH (start of heading)

2 00010010 STX (start of text)

3 00010011 ETX (end of text)

4 00010100 EOT (end of transmission)

5 00010101 ENQ (enquiry)

6 00010110 ACK (acknowledge)

7 00010111 BEL (bell)

8 00011000 BS (backspace)

9 00011001 HT (horizontal tab)

10 00011010 LF (line feed)

11 00011011 VT (vertical tab)

12 00011100 FF (form feed)

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 8
01
13 00011101 CR (carriage return)

14 00011110 SO (shift out)

15 00011111 SI (shift in)

16 00010000 DLE (data link escape)

17 00010001 DC1 (device control 1)

18 00010010 DC2 (device control 2)

19 00010011 DC3 (device control 3)

20 00010100 DC4 (device control 4)

21 00010101 NAK (negative acknowledge)

22 00010110 SYN (synchronous idle)

23 00010111 ETB (end of trans. block)

24 00011000 CAN (cancel)

25 00011001 EM (end of medium)

26 00011010 SUB (substitute)

27 00011011 ESC (escape)

28 00011100 FS (file separator)

29 00011101 GS (group separator)

30 00011110 RS (record separator)

31 00011111 US (unit separator)

ASCII TABLE 2

Dec Hex Bin Char

32 0020 00100000 (space)

33 0021 00100001 !

34 0022 00100010 "

35 0023 00100011 #

36 0024 00100100 $

37 0025 00100101 %

38 0026 00100110 &

39 0027 00100111 '

40 0028 00101000 (

41 0029 00101001 )

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 9
01
42 002A 00101010 *

43 002B 00101011 +

44 002C 00101100 ,

45 002D 00101101 -

46 002E 00101110 .

47 002F 00101111 /

48 0030 00110000 0

49 0031 00110001 1

50 0032 00110010 2

51 0033 00110011 3

52 0034 00110100 4

53 0035 00110101 5

54 0036 00110110 6

55 0037 00110111 7

56 0038 00111000 8

57 0039 00111001 9

58 003A 00111010 :

59 003B 00111011 ;

60 003C 00111100 <

61 003D 00111101 =

62 003E 00111110 >

63 003F 00111111 ?

64 0040 01000000 @

65 0041 01000001 A

66 0042 01000010 B

67 0043 01000011 C

68 0044 01000100 D

69 0045 01000101 E

70 0046 01000110 F

71 0047 01000111 G

72 0048 01001000 H

73 0049 01001001 I

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 10
01
74 004A 01001010 J

75 004B 01001011 K

76 004C 01001100 L

77 004D 01001101 M

78 004E 01001110 N

79 004F 01001111 O

80 0050 01010000 P

81 0051 01010001 Q

82 0052 01010010 R

83 0053 01010011 S

84 0054 01010100 T

85 0055 01010101 U

86 0056 01010110 V

87 0057 01010111 W

88 0058 01011000 X

89 0059 01011001 Y

90 005A 01011010 Z

91 005B 01011011 [

92 005C 01011100 \

93 005D 01011101 ]

94 005E 01011110 ^

95 005F 01011111 _

96 0060 01100000 `

97 0061 01100001 a

98 0062 01100010 b

99 0063 01100011 c

100 0064 01100100 d

101 0065 01100101 e

102 0066 01100110 f

103 0067 01100111 g

104 0068 01101000 h

105 0069 01101001 i

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 11
01
106 006A 01101010 j

107 006B 01101011 k

108 006C 01101100 l

109 006D 01101101 m

110 006E 01101110 n

111 006F 01101111 o

112 0070 01110000 p

113 0071 01110001 q

114 0072 01110010 r

115 0073 01110011 s

116 0074 01110100 t

117 0075 01110101 u

118 0076 01110110 v

119 0077 01110111 w

120 0078 01111000 x

121 0079 01111001 y

122 007A 01111010 z

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 12
01
💠 NOTE

ASCII stands for American Standard Code for Information Interchange


and is a standardized code for representing characters in computers
and other devices

Each character in the ASCII table is represented by a unique number


between 0 and 127

For example, the letter "A" is represented by the number 65, and the
letter "B" is represented by the number 66

ASCII codes are usually represented using the binary numbering


system

ASCII is used in various contexts, including text files, email messages,


and web pages

ASCII is a widely used and widely supported standard, making it easy


to exchange text and other data between different devices and
systems.

UNICODE [00:21:38]
Unicode is a computing industry standard for the consistent encoding,
representation, and handling of text expressed in most of the world's writing
systems. Unicode provides a unique number for every character, no matter what
platform, device, application, or language you are using.

Unicode includes ASCII and many other characters from a variety of scripts and
symbols. Unicode defines more than 128,000 different characters, including the
ASCII characters, which are the first 128 characters of the Unicode character set.

RGB [00:26:10]
RGB stands for red, green, and blue. It is a color model used in digital imaging and
computer graphics to represent colors using a combination of red, green, and blue
light. In the RGB color model, each color is represented by a value between 0 and
255, which corresponds to the intensity of that color. For example, (255, 0, 0)
represents pure red, (0, 255, 0) represents pure green, and (0, 0, 255) represents
pure blue. By combining different levels of red, green, and blue, it is possible to

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 13
01
create a wide range of colors.

The RGB color model is widely used because it is supported by most computer
displays and many other devices, such as printers and digital cameras. It is also
often used in web design and other types of digital media.

MIDI [31:24]
MIDI (Musical Instrument Digital Interface) is a technical standard that describes a
protocol, a digital interface, and a connector for communicating musical information.
MIDI allows computers, synthesizers, and other electronic musical instruments to
communicate with each other and to store, edit, and playback music.
MIDI messages are sent via a MIDI cable, which is a standard 5-pin DIN cable. MIDI
messages are made up of 8-bit words that are organized into two 4-bit nibbles. The
first nibble is the status nibble, which specifies the type of message being sent, and
the second nibble is the data nibble, which contains the actual data being
transmitted.

There are several types of MIDI messages, including:

Note On/Off: these messages specify which note is being played and whether it
is being turned on or off

Control Change: these messages are used to control various parameters of a


MIDI device, such as the volume or the timbre

Program Change: these messages specify which instrument patch (i.e., sound)
is being used

Pitch Bend: these messages specify how the pitch of a note is being bent

MIDI has been widely used in the music industry since the 1980s, and it is still in
widespread use today.

Psedo Code [44:35]


Pseudocode is a way of describing a computer program or algorithm using a
combination of natural language and programming language-like elements. It is not
an actual programming language, but it is written in a way that is similar to a
programming language and can be easily understood by programmers.
Pseudocode is used to help plan and describe the steps of an algorithm, and it is
often used as a way to communicate ideas to other programmers. It is a useful tool

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 14
01
for helping to clarify and organize the logic of a program before actually writing it in a
programming language.
Here is an example of pseudocode that describes the steps of a program that
calculates the average of a list of numbers:
DEFINE sum as 0
DEFINE count as 0

FOR each number in the list


ADD the number to sum
INCREMENT count

SET average to sum / count


PRINT average

This pseudocode describes a program that goes through a list of numbers, adds
them up, and then divides the sum by the number of elements in the list to find the
average. It then prints the average.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 15
01
💠 NOTE

Unicode is a standard for encoding, representing, and handling text in


different writing systems

Unicode provides a unique number for every character, regardless of


platform or language

Unicode includes ASCII and over 128,000 other characters from


various scripts and symbols

RGB (red, green, blue) is a color model used in digital imaging and
graphics to represent colors using a combination of red, green, and
blue light

In the RGB model, each color is represented by a value from 0 to 255,


corresponding to the intensity of the color

The RGB model is widely used and supported by many devices,


including computer displays, printers, and digital cameras

MIDI (Musical Instrument Digital Interface) is a standard for


communicating musical information between devices and storing,
editing, and playing back music

MIDI messages are sent via a standard 5-pin DIN cable and consist of
8-bit words organized into two 4-bit nibbles

There are various types of MIDI messages, including Note On/Off,


Control Change, Program Change, and Pitch Bend

MIDI has been widely used in the music industry since the 1980s and
is still in use today

Pseudocode is a way of describing a computer program or algorithm


using a combination of natural language and programming language-
like elements

Pseudocode is not an actual programming language but is written in a


way that is easily understood by programmers

Pseudocode is used to plan and describe the steps of an algorithm


and is often used to communicate ideas to other programmers

Pseudocode is a useful tool for clarifying and organizing the logic of a


program before implementing it in a programming language

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 16
01
Example of pseudocode: a program that calculates the average of a
list of numbers by adding up the numbers, dividing the sum by the
number of elements in the list, and printing the result.

Introduction to the Scratch programming language


Scratch is a free, block-based programming language and online community
developed by the Lifelong Kindergarten group at the Massachusetts Institute of
Technology (MIT). It is designed to be easy to use and to help young people (ages 8
and up) learn programming concepts as they create interactive stories, games, and
animations.
In Scratch, code is written using blocks that snap together like puzzle pieces. Each
block represents a piece of code, such as an action, a loop, or a condition. Users
can drag and drop blocks to create programs, and can also use Scratch to control
the movement and appearance of characters on the screen.
Scratch has a large online community where users can share their projects, get
feedback from others, and participate in online challenges and events. It is a popular
tool for teaching programming to beginners, and is used in schools and other
educational settings around the world.

Functions
In Scratch, a function is a block of code that performs a specific task and can be
reused in different parts of a program. Functions are a key concept in programming,
as they allow you to break down a large program into smaller, more manageable
pieces.
In Scratch, you can define your own functions using the "define" block, which is
found in the "More Blocks" category. To create a function, you first give it a name and
then add the blocks of code that you want the function to execute when it is called.

Here is an example of how you might define a function in Scratch:


define myFunction
move 10 steps
say "Hello, world!"
end
This function is called "myFunction" and consists of two blocks of code: one that
moves a character 10 steps, and one that makes the character say "Hello, world!".

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 17
01
To use this function in your program, you can simply drag and drop the "myFunction"
block wherever you want the code to be executed. For example, you might use the
function in a loop to make the character say "Hello, world!" multiple times.
Functions are a powerful tool in Scratch and can help you write more organized,
efficient code. They are especially useful when you have a block of code that you
want to use in multiple places in your program, as they allow you to reuse that code
without having to copy and paste it.

Variables
In the Scratch programming language, a variable is a piece of information that can
change, like a number or a string of text. You can use variables to store data, make
your programs more flexible and easier to read, and perform mathematical
operations.
In Scratch, you can create variables by clicking on the "Data" category in the blocks
palette, and then clicking on the "Make a Variable" button. You can also create
variables by right-clicking on the blocks palette and selecting "New Variable".

Once you have created a variable, you can use it in your program by dragging the
variable block from the blocks palette and placing it in your script. You can use the
"set" block to change the value of a variable, and the "change" block to modify the
value of a variable by a certain amount.

You can use variables in a number of ways in Scratch, such as:

Storing and displaying data, like a score in a game

Controlling the behavior of your program, like changing the speed of a sprite
based on user input

Performing mathematical operations, like adding two numbers together.

Boolean expressions
In the Scratch programming language, a boolean expression is a statement that
evaluates to either "true" or "false". Boolean expressions are often used to test
conditions and control the flow of a program.
In Scratch, you can use boolean expressions by using the "true" and "false" blocks
from the "Looks" category in the blocks palette. You can also create boolean
expressions using comparison operators, such as "=", ">", "<", "≥", and "≤".

Here are some examples of boolean expressions in Scratch:

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 18
01
"Sprite1 is touching Sprite2" - This expression will be "true" if Sprite1 is touching
Sprite2, and "false" if Sprite1 is not touching Sprite2.

"Mouse down?" - This expression will be "true" if the mouse button is being
pressed, and "false" if the mouse button is not being pressed.

"Variable1 < Variable2" - This expression will be "true" if the value of Variable1 is
less than the value of Variable2, and "false" if the value of Variable1 is greater
than or equal to the value of Variable2.

You can use boolean expressions in conjunction with control blocks, such as "if" and
"if-else", to execute different code paths based on the evaluation of the boolean
expression.

Conditionals
In the Scratch programming language, a conditional is a type of control structure that
allows you to execute different code paths based on the evaluation of a boolean
expression.
In Scratch, you can use the "if" block to execute a code path if a boolean expression
is "true", and the "if-else" block to execute one code path if a boolean expression is
"true" and another code path if the boolean expression is "false".

Here's an example of how you might use a conditional in Scratch:

if <mouse down?>
move (10) steps
else
say [Hello!] for (2) seconds

In this example, the sprite will move 10 steps if the mouse button is being pressed
and say "Hello!" for 2 seconds if the mouse button is not being pressed.
You can use conditionals to test for a wide variety of conditions in Scratch, such as
the value of a variable, the position of a sprite, or the presence of a particular sprite
on the stage.

Loops, and events


In the Scratch programming language, loops are control structures that allow you to
repeat a section of code a certain number of times, or until a certain condition is met.
There are several types of loops available in Scratch, including:

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 19
01
"forever" loops, which repeat a block of code indefinitely

"repeat" loops, which repeat a block of code a certain number of times

"while" loops, which repeat a block of code until a certain condition is met

You can use loops to repeat actions, such as moving a sprite or playing a sound, or
to perform a series of actions in a certain order.
In Scratch, you can use the "forever" block to create a forever loop, the "repeat"
block to create a repeat loop, and the "while" block to create a while loop.
Here's an example of a forever loop in Scratch:

forever
move (10) steps
turn right (15) degrees

In this example, the sprite will move 10 steps and turn right 15 degrees indefinitely.
As for events, Scratch includes a number of "event blocks" that allow you to trigger
code execution based on certain events, such as the start of the program, the press
of a key, or the receipt of a message.
For example, you can use the "when flag clicked" block to execute a code path when
the green flag is clicked, or the "when [space] key pressed" block to execute a code
path when the space key is pressed.

Week 1 C [1:47:45]
Correctness [1:50:00]
In programming, correctness refers to the quality of a program or algorithm in
producing the correct results when it is executed. A program is considered valid if it
has the expected output for a given set of inputs and follows the rules and
conventions of the programming language it is written in.

There are several ways to ensure the correctness of a program, including:

Testing: This involves running the program with a variety of inputs and verifying
that the output is correct.

Debugging: This involves finding and fixing errors (also known as bugs) in the
program.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 20
01
Code review: This involves having other programmers review and critique the
code to ensure that it is correct and follows good programming practices.

Documentation: This involves writing clear and accurate documentation for the
program, including explanations of the algorithms and data structures used, to
help ensure that the program is understood and can be maintained over time.

Ensuring the correctness of a program is essential because it helps to ensure that


the program will function as intended and produce the desired results.

💠 NOTE

Correctness in programming refers to a program producing the


expected results for a given set of inputs.

Ways to ensure correctness include: testing, debugging, code review,


and documentation.

Ensuring correctness is essential for a program to function as


intended and produce desired results.

Adopting software development methodologies can also aid in


ensuring the quality and correctness of a program.

Design
In programming, design refers to the process of planning and organizing the
structure and features of a program or system. Design is an important part of the
software development process and involves identifying the requirements of the
program, determining the best solution to meet those requirements, and creating a
plan to implement that solution.
There are several different approaches to software design, including:

Object-oriented design: This approach involves designing the program around


"objects," which are self-contained entities that represent real-world concepts
and encapsulate data and behavior.

Structured design: This approach involves breaking the program down into
smaller, independent parts that can be easily understood and modified.

Model-view-controller (MVC) design: This approach involves separating the


program into three parts: the model, which represents the data and behavior of

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 21
01
the program; the view, which represents the user interface; and the controller,
which mediates between the model and the view.

Good design is important because it helps to make a program more maintainable,


scalable, and easy to understand.

💠 NOTE

Design in programming refers to the process of planning and


organizing the structure and features of a program or system.

Different approaches to software design include object-oriented


design, structured design, and model-view-controller (MVC) design.

Good design is important for making a program more maintainable,


scalable, and easy to understand.

Style
In programming, style refers to the conventions and guidelines used for writing and
formatting code. Style includes things like the use of indentation, naming
conventions, commenting, and the overall layout of the code.
There are several reasons why following a consistent style is important in
programming:

Clarity: A consistent style makes the code easier to read and understand, which
is important for maintaining and modifying the code over time.

Collaboration: When multiple people are working on the same codebase, having
a consistent style helps to reduce conflicts and makes it easier for everyone to
work together.

Quality: Adhering to a consistent style helps to ensure that the code is of high
quality and follows good programming practices.

There are several widely used style guides for different programming languages,
such as the Google Python Style Guide and the Airbnb JavaScript Style Guide. It is
a good idea to follow a style guide when writing code to ensure that it is consistent
and easy to read.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 22
01
💠 NOTE

Style in programming refers to the conventions and guidelines used


for writing and formatting code.

Having a consistent style is important for clarity, collaboration, and


quality of the code.

Following widely used style guides for different programming


languages is a good idea to ensure consistency and readability.

Conclusion
Correctness, design, and style are all related in that they all contribute to the overall
quality of a program.
Correctness is essential because it ensures that the program will produce the
desired results. If a program is not correct, it will not function as intended and may
produce incorrect or unexpected results.
Design is important because it determines the structure and organization of the
program, which in turn affects its correctness, maintainability, and scalability. A well-
designed program is easier to understand, modify, and debug, which helps to ensure
its correctness.
Style is important because it affects the readability and understandability of the code,
which is important for maintaining and modifying the program over time. A consistent
style makes the code easier to read and understand, which in turn helps to ensure
its correctness.
In short, good design and style contribute to the overall quality and correctness of a
program by making it easier to understand and maintain.

Using Visual Studio Code for coding in C [01:53:48]


Visual Studio Code (VSCode) is a popular, open-source code editor that can be used
for coding in C, as well as many other programming languages. Here are some of
the features of VSCode that make it a good choice for coding in C:

IntelliSense: VSCode has built-in IntelliSense, which is a feature that provides


code suggestions, parameter hints, and other forms of code assistance. This can
help you write code more quickly and accurately.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 23
01
Debugging: VSCode has a built-in debugging tool that allows you to set
breakpoints, step through your code, and inspect variables. This can help you
find and fix errors in your code more easily.

Extensions: VSCode has a large ecosystem of extensions that can be added to


the editor to add additional functionality. There are many extensions available for
C/C++ development that can help you with things like code formatting, linting,
and code snippets.

Integrated Terminal: You can run C language code by using the terminal in
VSCode. It allows you to run commands and tasks directly inside the editor.

Customizable: VSCode is highly customizable, you can customize the editor to


suit your needs by adjusting settings and installing extensions.

To start using VSCode for C development, you'll need to install the C/C++ extension.
Once you've done that, you can start creating new C projects, editing C source code,
and building and running your programs directly from within VSCode. It's a good idea
to also install a linter to help you with potential errors before you even run your code,
like c/c++ extension, cpplint, cppcheck.

💠 NOTE

Visual Studio Code (VSCode) is a popular open-source code editor


that can be used for coding in C.

Features of VSCode that make it a good choice for coding in C include


IntelliSense, debugging, extensions, integrated terminal, and
customizability.

To start using VSCode for C development, you'll need to install the


C/C++ extension.

An additional extensions like cpplint, cppcheck, Clang-format can be


added to check for errors and improve the quality of the code.

You can create, edit, build and run C programs directly from within
VSCode.

Syntax highlighting in code editors

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 24
01
Syntax highlighting is a feature found in many code editors that is used to visually
distinguish different parts of the code based on their syntax. This makes it easier for
developers to read and understand the code by providing a visual cue for different
elements of the language, such as keywords, comments, variables, and functions.

In a code editor, different parts of the code are typically assigned different colors or
font styles to indicate their syntax. For example, keywords may be colored blue,
comments may be colored green, and strings may be colored red. This makes it
easy to quickly identify different parts of the code and understand its meaning.

Most code editors nowadays have built-in syntax highlighting for various languages,
including C. But if you are using a code editor that doesn't have built-in syntax
highlighting for C, you can often install a plugin or extension to add syntax
highlighting for C.

Syntax highlighting can also be customized, many editors have settings where you
can adjust the color scheme, or create your own color scheme that makes it easy for
you to read and understand the code.

In addition to syntax highlighting, many code editors also have other features to help
you write and read code more easily, such as code folding, code snippets, code
completion, and go-to-definition.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 25
01
💠 NOTE

Syntax highlighting is a feature in code editors that helps to distinguish


different parts of the code based on their syntax.

Different parts of the code are assigned different colors or font styles
to indicate their syntax.

This feature makes it easy to quickly identify different parts of the code
and understand its meaning.

Most code editors have built-in syntax highlighting for various


languages, including C, but if not, you can install a plugin or extension
for it.

Syntax highlighting can also be customized, many editors have


settings where you can adjust the color scheme, or create your own
color scheme.

Other features like code folding, code snippets, code completion, and
go-to-definition can also be found in many code editors to make the
coding experience easier.

"Hello, World!"
"Hello, World!" program written in C:

#include <stdio.h>int
int main(void)
{
printf("Hello, World!\n");
}

To compile and run this program, you would first save it to a file with a .c extension
(for example, hello.c ), and then use a C compiler to compile it. For example, on a
Unix-like system, you could use the following command to compile the program:

gcc hello.c -o hello

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 26
01
This would create an executable file called hello , which you could then run by
typing ./hello at the command prompt. When you run the program, it should print
"Hello, World!" to the console.

Integrated Development Environment [1:53:38]


An Integrated Development Environment (IDE) is a software application that
provides a comprehensive set of tools for software development. IDEs typically
include a code editor, a compiler or interpreter, a debugger, and other tools that are
necessary for software development.

Some of the benefits of using an IDE include:

Code completion: Many IDEs provide code completion features, which suggest
code snippets or complete statements as you type, to help you write code more
quickly and accurately.

Debugging: IDEs often include debugging tools that allow you to step through
your code, set breakpoints, and inspect variables to help you find and fix errors.

Project management: IDEs often provide features for managing and organizing
your code, such as the ability to create projects, manage files, and navigate
through your code more easily.

Integration: IDEs often provide integration with other tools, such as version
control systems, build systems, and testing frameworks, to help streamline the
development process.

Some popular IDEs include Eclipse, Visual Studio, and Xcode.

💠 NOTE

An Integrated Development Environment (IDE) is a software


application that provides comprehensive tools for software
development, including a code editor, compiler/interpreter, debugger,
and other tools.

Some benefits of using an IDE include code completion, debugging,


project management, and integration with other tools.

Popular IDEs include Eclipse, Visual Studio, and Xcode.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 27
01
Command Line Interface (CLI) [2:00:20] [02:38:09]
A Command Line Interface (CLI) is a text-based interface for interacting with a
computer or operating system. It allows you to enter commands using a keyboard,
and the computer or operating system responds by performing the requested
actions.

CLIs are typically used in a terminal or command prompt window, and they are often
preferred by experienced users and developers because they offer more control and
flexibility than graphical user interfaces (GUIs).

To use a CLI, you enter commands by typing them into the terminal window and
pressing the Enter key. The command is then executed, and the output is displayed
in the terminal window.
Some examples of common CLI commands include:

ls : List the files and directories in the current directory

cd : Change the current directory

mkdir : Create a new directory

rm : Remove a file or directory

man : Display the manual for a command

CLIs are often used to perform advanced tasks and automate processes, and they
are commonly used in conjunction with scripts and programming languages.

💠 NOTE

Command Line Interface (CLI) is a text-based interface for interacting


with a computer or operating system using commands entered
through a terminal or command prompt window.

CLI offers more control and flexibility than graphical user interfaces
(GUIs) and is preferred by experienced users and developers.

Common CLI commands include: ls , cd , mkdir , rm , man .

CLI is often used to perform advanced tasks and automate processes,


and it is commonly used in conjunction with scripts and programming
languages.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 28
01
“./ “command [02:01:27]
In a C program ./ is used to specify the current directory when running an
executable file. For example, if you have compiled a C program and created an
executable file called myprogram , you can run the program by typing ./myprogram at
the command prompt.
The ./ notation is used to indicate that the file is located in the current directory. If
you omit the ./ , the operating system may not be able to find the file, especially if it
is not in one of the directories listed in the PATH environment variable.

Here is an example of running a C program using ./ :

$ gcc myprogram.c -o myprogram


$ ./myprogram

The first command compiles the C program and creates an executable file called
myprogram . The second command runs the myprogram executable.

Graphical User Interface (GUI)


A Graphical User Interface (GUI) is a type of user interface that allows users to
interact with a computer or operating system through the use of visual elements
such as windows, icons, and menus. GUIs are typically easier to use than command
line interfaces (CLIs), as they allow users to perform tasks using a mouse or
touchpad rather than typing commands.

Some examples of common features of a GUI include:

Windows: These are rectangular areas that can be opened, closed, minimized,
and resized on the screen. Each window typically contains a specific application
or document.

Icons: These are small graphics that represent applications, files, or actions.
Users can typically click on an icon to open an application or perform a task.

Menus: These are lists of options that can be accessed by clicking on a button or
menu bar.

Pointers: These are graphical objects that appear on the screen and allow users
to interact with the GUI by pointing and clicking on objects.

Some popular operating systems with GUI interfaces include Windows, macOS, and
Linux with a desktop environment such as GNOME or KDE.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 29
01
💠 NOTE

Graphical User Interface (GUI) is a type of user interface that allows


users to interact with a computer or operating system using visual
elements such as windows, icons, and menus.

GUI is typically easier to use than command line interfaces (CLIs) as it


allows users to perform tasks using a mouse or touchpad instead of
typing commands.

Common features of a GUI include windows, icons, menus, and


pointers.

Popular operating systems with GUI interfaces include Windows,


macOS, and Linux with a desktop environment such as GNOME or
KDE.

Source Code & Matchin Code


Source code is human-readable text that is written in a programming language. It is
the code that is written by a programmer and is used to create a program or
application. Source code consists of a series of instructions that tell a computer what
to do, and it is written in a high-level programming language that is easy for humans
to read and understand.

Machine code, also known as machine language or object code, is the low-level
code that is directly executed by a computer's central processing unit (CPU). It
consists of a series of binary digits (ones and zeros) that represent the instructions
that the CPU is to execute. Machine code is not easy for humans to read or
understand, as it consists of a series of numbers and symbols that have no meaning
to us.

To create a program, a programmer writes the source code in a text editor and then
uses a compiler to translate the source code into machine code. The machine code
is then saved as an executable file, which can be run on a computer to perform the
tasks specified in the source code.

In summary, source code is the human-readable code that is written by a


programmer, while machine code is the low-level code that is executed by a
computer's CPU.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 30
01
💠 NOTE

Source code is a human-readable text written in a programming


language, used to create a program or application.

Machine code also known as machine language or object code, is


low-level code consisting of binary digits that are executed directly by
a computer's CPU.

To create a program, a programmer writes the source code in a text


editor and then uses a compiler to translate the source code into
machine code.

Machine code is saved as an executable file that can be run on a


computer to perform the tasks specified in the source code.

In summary, source code is human-readable while machine code is


low-level code that is executed by a computer's CPU.

Function [02:08:17]
In C, a function is a block of code that performs a specific task and optionally returns
a value. Functions are a useful way to organize and reuse code, as they allow you to
define a set of instructions once and then call them multiple times from different parts
of your program.

Here is an example of a simple function in C that calculates the area of a rectangle:

int area(int width, int height)


{
return width * height;
}

This function, called area , takes two arguments: width and height , which represent
the width and height of the rectangle. The function calculates the area of the
rectangle by multiplying the width and height and then returns the result using the
return statement.

To call a function in C, you use the function's name followed by a set of parentheses
containing the arguments. For example, to call the area function with arguments 3
and 4 , you would write:

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 31
01
int result = area(3, 4);

This would call the area function with the arguments 3 and 4 , and the result (12)
would be stored in the variable result .

💠 NOTE

In C, a function is a block of code that performs a specific task and


optionally returns a value.

Functions are a useful way to organize and reuse code, allowing you
to define a set of instructions once and then call them multiple times
from different parts of your program.

The function's syntax includes the return type, name, and parameters.

To call a function in C, you use the function's name followed by


parentheses containing the arguments.

Functions can be used to make code more readable, easy to maintain,


and debug.

Argument
In programming, an argument is a value or expression that is passed to a function or
method when it is called. Arguments are used to provide additional information or
context to the function or method, and they are typically used to customize or modify
the behavior of the function or method.

For example, consider the following C function that takes two arguments:

int add(int x, int y)


{
return x + y;
}

In this example, x and y are the arguments of the add function. When the add
function is called, it expects the caller to pass two integer values, which are then
stored in the variables x and y . The function then adds these values together and
returns the result.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 32
01
Here is an example of calling the add function with arguments:

int result = add(3, 4);

In this example, the add function is called with arguments 3 and 4 . The function
adds these values together and returns the result, which is then stored in the
variable result .

Arguments are an important concept in programming, as they allow functions and


methods to be reusable and flexible by allowing the caller to customize their
behavior.

💠 NOTE

Arguments are values or expressions passed to a function or method


when called

They provide additional information or context to the function or


method

Used to customize or modify the behavior of the function or method

Example: In the C function int add(int x, int y) , x and y are


arguments. When called, the function expects two integer values
which are then added together and returned.

String [02:09:26]
In C programming, a string is a sequence of characters that is stored in an array and
is used to represent and manipulate text. Strings are an important data type in C,
and they are used in a wide variety of applications.

To declare a string in C, you can use the following syntax:

char str[10];

This creates an array called str that is capable of holding up to 10 characters. To


assign a value to the string, you can use the following syntax:

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 33
01
char str[10] = "Hello";

This assigns the string "Hello" to the str array. It is important to note that the size of
the array must be sufficient to hold the string and the null terminator character
( '\0' ), which indicates the end of the string.

To access the characters in a string, you can use array notation, like this:

char c = str[0];

This retrieves the first character of the str array (the letter 'H') and assigns it to the
variable c .
Strings are an important aspect of C programming, and there are numerous built-in
functions available for manipulating and formatting them. Examples of string
functions include strlen , which returns the length of a string, and strcat , which
concatenates (joins) two strings.

Side Effects
In programming, a side effect is an effect of a function or operation that is not the
primary purpose of the function or operation. Side effects can occur when a function
or operation modifies something outside of its local scope, such as a global variable
or an external resource.

Side effects can be intentional or unintentional, and they can have a variety of
consequences. For example, a function might have the primary purpose of
performing a calculation, but it might also have the side effect of updating a global
variable or writing to a file.
In general, it is generally considered good programming practice to minimize side
effects, as they can make code more difficult to understand and debug. This is
because side effects can have unintended consequences, and they can make it
harder to predict the behavior of a program.

For example, consider the following function:

int add(int x, int y)


{
global_sum += x + y;
return x + y;
}

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 34
01
This function has the primary purpose of adding two numbers and returning the
result. However, it also has the side effect of updating the global variable global_sum
with the sum of the two numbers. This side effect might be intentional, but it can
make the function more difficult to understand and predict, as the value of global_sum
will be affected every time the function is called.

💠 NOTE

Side effects in programming refer to an effect of a function or


operation that is not the primary purpose of the function or operation.

They can occur when a function or operation modifies something


outside of its local scope, such as a global variable or an external
resource.

Side effects can be intentional or unintentional and can have a variety


of consequences.

It is considered good programming practice to minimize side effects as


they can make code more difficult to understand, predict and debug.

Examples of side effects can include updating global variables or


writing to a file.

Return Value [02:10:45]


In programming, a return value is a value that is returned by a function or method
when it is called. Return values are used to communicate the result of a function or
method to the caller, and they are typically used to indicate the success or failure of
the function or method or to return a computed result.
In most programming languages, functions and methods are defined with a return
type, which specifies the data type of the return value. For example, a function might
have a return type of int , which indicates that it returns an integer value.

To return a value from a function or method, you can use the return statement. For
example, consider the following C function:

int add(int x, int y)


{

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 35
01
return x + y;
}

This function takes two arguments, x and y , and returns their sum. The return

statement indicates that the function should return the value of x + y to the caller.
To use the return value of a function or method, you can assign it to a variable or use
it in an expression. For example:

int result = add(3, 4);

This calls the add function with the arguments 3 and 4 , and assigns the return
value (7) to the variable result .

💠 NOTE:

In programming, a return value is a value that is returned by a function


or method when it is called.

Return values are used to communicate the result of a function or


method to the caller, and they are typically used to indicate the
success or failure of the function or method or to return a computed
result.

Functions and methods are usually defined with a return type, which
specifies the data type of the return value.

To return a value from a function or method, you can use the return

statement.

To use the return value of a function or method, you can assign it to a


variable or use it in an expression.

It is generally considered good programming practice to clearly


document the return value of a function or method in its
documentation.

“=” Sign means [02:12:46]


In C, the = sign is the assignment operator, which is used to assign a value to a
variable. The assignment operator has the following syntax:

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 36
01
variable = value;

Here, variable is the name of the variable to which the value should be assigned,
and value is the value to be assigned. The value on the right side of the = sign is
assigned to the variable on the left side.

For example, consider the following C code:

int x = 5;

This code uses the assignment operator to assign the value 5 to the variable x .
After this assignment, the value of x will be 5 .

It is important to note that the = sign should not be confused with the == sign, which
is the equality operator. The equality operator is used to test if two values are equal,
and it has the following syntax:

if (x == y)
{
// do something
}

Here, x and y are compared to see if they are equal. If they are equal, the code
inside the if statement will be executed. If they are not equal, the code will be
skipped.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 37
01
💠 NOTE:

In C programming, the = sign is the assignment operator.

The assignment operator is used to assign a value to a variable.

The syntax for the assignment operator is variable = value; , where


variable is the name of the variable to be assigned, and value is the

value to be assigned.

The value on the right side of the = sign is assigned to the variable on
the left side.

The = sign should not be confused with the == sign, which is the
equality operator.

The equality operator is used to test if two values are equal, and its
syntax is: if (x == y) { ... } , where x and y are the values to be
compared. If x and y are equal, the code inside the if statement is
executed; otherwise, the code is skipped.

\n Means [02:16:43]
In C, \n is a special escape sequence that represents a newline character. When a
string containing \n is printed, the output is displayed on a new line.
For example, consider the following C code:

#include <stdio.h>int main()


{
printf("Hello\nWorld");
return 0;
}

This code prints the string "Hello\nWorld" to the console. Because the string contains
the \n escape sequence, the output is displayed on two separate lines:

Hello
World

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 38
01
The \n escape sequence can be used anywhere within a string to force a line
break. For example:

printf("Line 1\nLine 2\nLine 3");

This code would output the following:

Line 1
Line 2
Line 3

Escape sequences are used to represent special characters that cannot be typed
directly into a string, such as a newline ( \n ), tab ( \t ), and backslash ( \\ ). There
are many other escape sequences in C, and you can find a complete list in the
documentation for the printf function.

💠 NOTE:

In C programming, \n is an escape sequence that represents a


newline character.

When a string containing \n is printed, the output is displayed on a


new line.

The \n escape sequence can be used anywhere within a string to


force a line break.

Escape sequences are used to represent special characters that


cannot be typed directly into a string, such as newline ( \n ), tab ( \t ),
and backslash ( \\ ).

There are many other escape sequences in C, and a complete list can
be found in the documentation for the printf function.

<sdtio.h> Means [02:22:44]


stdio.h is a header file in the C standard library. It stands for "Standard Input/Output
Header" and contains definitions and prototypes for functions used for input and
output in C programs.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 39
01
The stdio.h header file is a standard part of most C compilers and is included in
many C programs using the #include preprocessor directive. For example:

#include <stdio.h>int main()


{
printf("Hello, World!");
return 0;
}

In this example, the stdio.h header file is included at the top of the program, and the
printf function is used to print the string "Hello, World!" to the console. The printf

function is defined in the stdio.h header file, so it must be included in order to use it.
The stdio.h header file contains a wide range of functions for input and output,
including functions for reading and writing to the console, files, and other streams.
Some examples of functions defined in stdio.h include printf , scanf , fprintf ,
fscanf , and puts .

💠 NOTE:

stdio.h is a header file in the C standard library.

It stands for "Standard Input/Output Header" and contains definitions


and prototypes for functions used for input and output in C programs.

The stdio.h header file is a standard part of most C compilers and is


included in many C programs using the #include preprocessor
directive.

The stdio.h header file contains a wide range of functions for input
and output, including functions for reading and writing to the console,
files, and other streams.

Examples of functions defined in stdio.h include printf , scanf ,


fprintf , fscanf , and puts .

<sc50.h> Means
is a header file used in the CS50 library, which is a set of tools and libraries
<cs50.h>

for computer science education. The CS50 library is used in the Introduction to

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 40
01
Computer Science course (CS50) at Harvard University, and it is designed to make it
easier to teach and learn computer science concepts.

The <cs50.h> header file contains definitions and prototypes for a variety of functions
and data types that are used in the CS50 course. These functions and data types
are designed to provide a simple and consistent interface for performing common
tasks in C programming.

For example, the <cs50.h> header file defines the string data type, which is a
convenient way to represent and manipulate strings in C. It also defines functions
such as GetString , which reads a string from the user, and GetInt , which reads an
integer from the user.

To use the <cs50.h> header file in a C program, you can include it at the top of your
program using the #include preprocessor directive. For example:

#include <cs50.h>int main() {


string name = GetString();
printf("Hello, %s!\n", name);
return 0;
}

This code includes the <cs50.h> header file and uses the GetString function to read
a string from the user. The string is then printed to the console using the printf

function.

💠 NOTE:

<cs50.h> is a header file used in the CS50 library, which is a set of


tools and libraries for computer science education.

The CS50 library is used in the Introduction to Computer Science


course (CS50) at Harvard University, and it is designed to make it
easier to teach and learn computer science concepts.

The <cs50.h> header file contains definitions and prototypes for a


variety of functions and data types that are used in the CS50 course.

These functions and data types are designed to provide a simple and
consistent interface for performing common tasks in C programming.

To use the <cs50.h> header file in a C program, you can include it at


the top of your program using the #include preprocessor directive.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 41
01
%s Means [02:24:00]
In C programming, %s is a placeholder in a format string that represents a string. It is
used in conjunction with the printf function to print a string to the console.

The printf function is a standard C function that is used to print output to the
console. It takes a format string as its first argument, followed by a list of arguments
corresponding to the format string's placeholders.

The %s placeholder is used to indicate that a string argument should be inserted into
the output at that point. For example, consider the following code:

#include <stdio.h>int main()


{
char *name = "John";
printf("Hello, %s!\n", name);
return 0;
}

This code defines a string variable called name and assigns it the value "John". It
then uses the printf function to print the string "Hello, John!" to the console. The %s

placeholder in the format string is replaced with the value of the name variable.

The printf function can take many different placeholders, including %s for strings,
%d for integers, %f for floating-point numbers, and %c for characters. You can find a

complete list of placeholders in the documentation for the printf function.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 42
01
💠 NOTE:

In C programming, %s is a placeholder in a format string that


represents a string.

It is used in conjunction with the printf function to print a string to the


console.

The printf function takes a format string as its first argument,


followed by a list of arguments corresponding to the format string's
placeholders.

The %s placeholder is used to indicate that a string argument should


be inserted into the output at that point.

The printf function can take many different placeholders, including


%s for strings, %d for integers, %f for floating-point numbers, and %c

for characters.

You can find a complete list of placeholders in the documentation for


the printf function.

printf means [02:25:00]


In the C programming language, printf is a function that is used to print a formatted
string to the standard output (usually the screen). The printf function takes a format
string as its first argument, which specifies how the subsequent arguments should
be formatted and displayed. The format string can include placeholders, called
conversion specifiers, that indicate where the values of the additional arguments
should be inserted. For example, the conversion specifier %d is used to print an
integer value, while %f is used to print a floating-point value.
Example:

printf("The value of x is: %d", x);

The above example would print the string "The value of x is:" followed by the value of
the integer variable x .

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 43
01
💠 NOTE

In C programming language, printf is a function used to print a


formatted string to the standard output (usually the screen).

printf takes a format string as its first argument, which specifies how
the subsequent arguments should be formatted and displayed.

The format string can include placeholders, called conversion


specifiers, that indicate where the values of the additional arguments
should be inserted.

Example: printf("The value of x is: %d", x); This will print "The value of
x is:" followed by the value of the integer variable x.

Syntax highlights
Syntax highlighting is a feature of some text editors and integrated development
environments (IDEs) that makes it easier to read and write code by applying different
colors and font styles to different parts of the code, such as keywords, operators,
comments, and strings.

The purpose of syntax highlighting is to help programmers distinguish between


different elements of the code and to quickly identify and correct errors, such as
mistyped keywords or missing punctuation. It can also make the code more readable
and easier to understand, by making it clear which parts of the code are responsible
for which functionality.

Different programming languages have their own syntax, and syntax highlighting
needs to be adjusted accordingly. It's supported by many source code editors and
IDEs like VSCode, Sublime, Atom, and many more.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 44
01
💠 NOTE

Syntax highlighting is a feature of text editors and IDEs that makes it


easier to read and write code by applying different colors and font
styles to different parts of the code.

The purpose of syntax highlighting is to help programmers distinguish


between different elements of the code and to quickly identify and
correct errors.

It can also make the code more readable and easier to understand.

Different programming languages have their own syntax, and syntax


highlighting needs to be adjusted accordingly.

Syntax highlighting is supported by many source code editors and


IDEs such as VSCode, Sublime, Atom, etc.

Header files [02:33:48]


In the C and C++ programming languages, a header file is a file that contains
declarations for functions, variables, and other constructs that can be shared across
multiple source files. The purpose of a header file is to separate the interface of a
module (i.e., the functions and data that it exports) from its implementation (i.e., the
code that actually defines how those functions and data behave).
A header file typically has a file name with the ".h" extension, but it is not necessary.
By convention, the name of a header file usually matches the name of the module
that it defines. For example, the standard C library has a header file called "stdio.h"
that contains declarations for functions and variables that are used for input and
output operations, such as printf and scanf.

A source file that wants to use the declarations in a header file has to include it using
preprocessor directive #include . The preprocessor looks for the header file in
predefined system paths and includes paths of the compiler.
Example:

#include <stdio.h>
int main()
{
printf("Hello, World!");

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 45
01
return 0;
}

In the above example, #include <stdio.h> directive tells the preprocessor to include
the contents of the "stdio.h" header file in this source file before the compiler
processes it.

💠 NOTE

In C and C++, a header file is a file that contains declarations for


functions, variables and other constructs that can be shared across
multiple source files.

The purpose of a header file is to separate the interface of a module


(exported functions and data) from its implementation (code that
defines how they behave).

Header files usually have a file name with the ".h" extension but it is
not necessary.

By convention, the name of a header file usually matches the name of


the module that it defines.

A source file that wants to use the declarations in a header file has to
include it using preprocessor directive #include.

The preprocessor looks for the header file in predefined system paths
and includes paths of the compiler.

How to navigate in CLI [02:38:09]


Navigating in the command-line interface (CLI) typically involves moving around the
file system and changing the current working directory. Here are some common
commands and techniques for navigating the file system in a CLI:

pwd : This command displays the current working directory, which is the directory
that the command-line prompt is currently set to.

cd : This command changes the current working directory. You can specify a
directory path as an argument to move to a specific directory. For example, cd
Documents will change the working directory to a directory called "Documents"

within the current working directory.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 46
01
ls : This command lists the contents of the current working directory. You can
also specify a directory path as an argument to list the contents of a specific
directory.

.. : This token represents the parent directory of the current working directory.
It can be used with cd command to move to the parent directory. For example,
cd .. will move to the parent directory of the current working directory.

. : This token represents the current working directory.

/ : This token represents the root directory of the file system. You can use it as
an argument for cd command to move to the root directory of the file system.
For example, cd / will move to the root directory.

Tab completion : It's a feature available in most command-line interpreters, It


allows you to the auto-complete directory or file names by pressing the Tab key.

pushd and popd : These commands that are used to navigate between
directories quickly. pushd allows you to switch to a new directory while also
keeping track of the previous directory and popd allows you to switch back to the
previous directory.

These are some of the most common commands and techniques for navigating in
the CLI, and it can be combined and used in conjunction with other commands,
options, and redirection and pipelining to perform more advanced tasks.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 47
01
💠 NOTE

Navigating in CLI involves moving around the file system and


changing the current working directory.

Common commands for navigation include: pwd , cd , ls , .. , . , / ,


Tab completion, pushd , and popd .

pwd shows the current working directory, cd change the current


working directory, ls lists the contents of the current working
directory, .. represents the parent directory, . represents the current
working directory, / represents the root directory.

Tab completion is a feature to auto-complete directory or file names by


pressing the Tab key.

pushd and popd are commands used to navigate between directories


quickly, pushd allows you to switch to a new directory while also
keeping track of the previous directory and popd allows you to switch
back to the previous directory.

These commands can be combined and used in conjunction with


other commands, options, and redirection and pipelining to perform
more advanced tasks.

DATA Types in C [02:43:35]


C programming language has a variety of built-in data types that are used to define
the type and size of variables. Here is a comprehensive list of data types in C:

Integer types:

char : It's a signed or unsigned integer type that typically has a size of 8
bits, but it can also be 16 or 32 bits in some systems. It's used to store
characters, ASCII values, and small integers.

short : It's a signed or unsigned integer type that typically has a size of 16
bits, it's used to store integers that are larger than char and smaller than
int .

int : It's a signed or unsigned integer type that typically has a size of 32
bits, it's the most common integer type used in C programs.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 48
01
long: It's a signed or unsigned integer type that typically has a size of 32 or
64 bits, it's used to store integers that are larger than int .

long long : It's a signed or unsigned integer type that typically has a size of
64 bits, it's used to store integers that are larger than long .

Floating-point types:

float : It's a 32-bit floating-point type, used to store decimal numbers with
single precision.

double: It's a 64-bit floating-point type, used to store decimal numbers with
double precision.

long double : it's an 80-bit or more precision floating point number, used to
store decimal numbers with more precision than double .

Pointer types:

void* : A pointer to any object, typically used as a generic pointer type.

type* : A pointer to an object of type type , where type can be any valid C
data type.

Array types:

: An array of objects of type


type[] type , where type can be any valid
C data type.

Structure types:

: A user-defined data type that can contain multiple members of


struct

different data types.

Union types:

: A user-defined data type that can contain multiple members of


union

different data types, but only one member can be active at a time.

Enumerated types:

: A user-defined data type that can contain a set of named integer


enum

constants.

Boolean types:

or bool : A type that can hold only two values, true and false , it's
_Bool

not a built-in data type in C but can be implemented using _Bool or bool
keyword, stdbool.h header defines it.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 49
01
Additionally, C also has some special keywords and qualifiers such as const ,
volatile , signed , unsigned , restrict that can be used to modify the behavior or

the properties of the data types.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 50
01
💠 NOTE

Integer types:

char : 8-bit integer, used to store characters and small integers.

short: 16-bit integer, used to store integers larger than char and
smaller than int .

int : 32-bit integer, commonly used to store integers.

long : 32/64-bit integer, used to store integers larger than int .

long long : 64-bit integer, used to store integers larger than long .

Floating-point types:

float : 32-bit floating point, used to store decimal numbers with


single precision.

double: 64-bit floating point, used to store decimal numbers with


double precision.

: 80-bit or more precision floating point, used to store


long double

decimal numbers with more precision.

Pointer types:

void* : Pointer to any data type.

Pointers to other data types ( int* , char* , float* etc.)

Array types:

type[]: An array of elements of a specified data type, size should


be specified.

Enumeration types:

enum : List of named integer constants.

Structure types:

struct: Collection of different data types, used to store different


values of different types in a single variable.

Union types:

union : Similar to struct, but all members share the same memory
location.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 51
01
Boolean type:

_Bool / bool : Can have only two values: true or false

It's important to note that in C the size and range of data types are
machine dependent, and the sign of integer variable can be specified
using signed and unsigned keywords.

CS50 library get functions [02:44;40]


The CS50 library provides a number of helpful input and output functions, one of
which is the get_* family of functions, which are used to read and validate input from
the user.

The get_* functions come in several variations such as:

get_int() : reads an integer from the user and returns it. It also checks for errors
such as non-numeric input, and prompts the user to re-enter the input until a
valid integer is received.

get_float() : reads a float value from the user and returns it. It also checks for
errors such as non-numeric input and prompts the user to re-enter the input until
a valid float value is received.

get_long_long() : reads a long long value from the user and returns it. It also
checks for errors such as non-numeric input and prompts the user to re-enter the
input until a valid long long value is received.

get_string() : reads a string of characters from the user and returns it. It also
checks for errors such as an empty string or input that exceeds a specified
maximum length and prompts the user to re-enter the input until a valid string is
received.

get_char() : reads a single character from the user and returns it. It also checks
for errors such as input that exceeds a specified maximum length and prompts
the user to re-enter the input until a valid character is received.

These functions are very convenient and easy to use, they prompt the user for input
and then validate that input before returning it to the program. They can save a lot of
time and simplify the process of reading input from the user, especially when it
comes to input validation.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 52
01
It's worth noting that for all these functions to work correctly, cs50.h must be included
in your code.

💠 NOTE

The CS50 library provides a number of helpful input and output


functions, one of which is the get_* family of functions, which are
used to read and validate input from the user.

The functions come in several variations such as get_int() ,


get_*

get_float() , get_long_long() , get_string() and get_char() .

These functions are very convenient and easy to use, they prompt the
user for input and then validate that input before returning it to the
program.

They can save a lot of time and simplify the process of reading input
from the user, especially when it comes to input validation.

To use these functions correctly, cs50.h must be included in your


code.

Format specifiers [02:45:15]


In the C programming language, there are several format specifiers that can be used
with the printf() and scanf() functions to control how data is formatted and read.
Some of the most commonly used format specifiers are:

%d or %i : This format specifier is used to print or read signed integers.

%u : This format specifier is used to print or read unsigned integers.

%f : This format specifier is used to print or read floating-point numbers.

%c : This format specifier is used to print or read a single character.

%s : This format specifier is used to print or read a string of characters.

%x or %X : This format specifier is used to print or read integers in hexadecimal


(base 16) notation.

%o : This format specifier is used to print or read integers in octal (base 8)


notation.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 53
01
%p : This format specifier is used to print or read a pointer.

%e or %E : This format specifier is used to print or read floating-point numbers in


scientific notation.

%g or %G : This format specifier is used to print or read floating-point numbers in


either fixed-point or scientific notation, whichever is shorter.

%i : This format specifier is used to print or read signed integers. It works the
same as %d .

%li : This format specifier is used to print or read signed long integers. It's
useful for larger integers.

%lu : This format specifier is used to print or read unsigned long integers.

%lld : This format specifier is used to print or read signed long long integers.

%llu : This format specifier is used to print or read unsigned long long integers.

The format specifiers should be used in combination with the printf() and scanf()

functions to print or read the data respectively. Also, it is important to match the type
of the variable with the format specifier when using these functions, otherwise, it may
lead to unexpected behavior or undefined behavior.

💠 NOTE

In C, format specifiers are used with the printf() and scanf() functions
to control how data is formatted and read.

Some commonly used format specifiers include %d or %i for signed


integers, %u for unsigned integers, %f for floating-point numbers, %c
for a single character, %s for a string of characters, %x or %X for
integers in hexadecimal notation, %o for integers in octal notation, %p
for a pointer, %e or %E for floating-point numbers in scientific notation,
%g or %G for floating-point numbers in either fixed-point or scientific
notation, %li for signed long integers, %lu for unsigned long integers,
%lld for signed long long integers, and %llu for unsigned long long
integers.

It's important to match the type of the variable with the format specifier
when using printf() or scanf() functions otherwise it may lead to
unexpected behavior or undefined behavior.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 54
01
Operators [02:45:50]
The following is a list of operators that are commonly used in C:

Arithmetic operators: +, -, *, /, %

Relational operators: ==, !=, >, <, >=, <=

Logical operators: &&, ||, !

Assignment operators: =, +=, -=, *=, /=, %=

Conditional operator: ? :

Bitwise operators: &, |, ^, ~, <<, >>

Miscellaneous operators: sizeof, &, *, ->, ., [] , ()

It's important to understand the precedence and associativity of operators when


writing expressions, as it can affect the outcome of your program.
For example, in arithmetic operations, the multiplication operator has higher
precedence than the addition operator, so the expression 3 * 4 + 2 would be
evaluated as 12 + 2 = 14

It's also important to use parentheses to group expressions and clarify the order of
operations.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 55
01
💠 NOTE

Operators are used to performing operations on variables and values


in C.

Commonly used operators include:

Arithmetic operators: +, -, *, /, %

Relational operators: ==, !=, >, <, >=, <=

Logical operators: &&, ||, !

Assignment operators: =, +=, -=, *=, /=, %=

Conditional operator: ? :

Bitwise operators: &, |, ^, ~, <<, >>

Miscellaneous operators: sizeof, &, *, ->, ., [] , ().

It's important to understand the precedence and associativity of


operators when writing expressions, as it can affect the outcome of
your program.

Use parentheses to group expressions and clarify the order of


operations.

Variable and Syntactic sugar [02:46:15]


In computer programming, a variable is a storage location in memory, with a specific
name, that can be used to store and retrieve a value. Variables are typically used to
store data that can change during the execution of a program.

The name of a variable is called an identifier and it must follow the rules for naming
variables in the specific programming language. In C, variable names can only
contain letters, digits, and the underscore character, and they cannot begin with a
digit.

Syntactic sugar is a term used to describe language features that make the code
more readable or convenient for the programmer but do not add any new
functionality. These features are not strictly necessary for the functioning of the
program, but they make it easier for the programmer to write and understand the
code.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 56
01
For example, C99 introduced a feature called "variable-length arrays" which allows
you to declare arrays whose size is determined at runtime. This is a new feature in C
that was not present in earlier versions of the language.

Another example is the for loop. In C, we can accomplish the same functionality of
a for loop with a while loop, but the for loop is more readable and thus more
convenient to use.
In short, Syntactic sugar is a way to make the code more readable and convenient
for the programmer, but it does not add any new functionality to the programming
language.

💠 NOTE

In computer programming, a variable is a storage location in memory


that can be used to store and retrieve a value.

Variables are typically used to store data that can change during the
execution of a program, and their name is called an identifier.

Syntactic sugar is a term used to describe language features that


make the code more readable or convenient for the programmer but
do not add any new functionality.

Examples of syntactic sugar in C are variable-length arrays and the for


loop which are not necessary but makes the code more readable and
convenient.

Syntactic sugar is a way to make the code more readable and


convenient for the programmer, but it does not add any new
functionality to the programming language.

Make Calculator Step by Step [02:50:10]


1. Open a text editor and create a new file named add.c .

2. Add the following line at the top of the file to include the CS50 library and the
standard input/output library:

#include <cs50.h>#include <stdio.h>

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 57
01
3. Define the main function and include the void argument:

int main(void)
{

4. Use the get_int function from the CS50 library to prompt the user to enter an
integer value for x . Store the value in a variable named x :

int x = get_int("Enter an x value: ");

5. Use the get_int function again to prompt the user to enter an integer value for
y . Store the value in a variable named y :

int y = get_int("Enter an y value: ");

6. Add the values of x and y and store the result in a variable named sum :

int sum = x + y;

7. Use the printf function to print the result using the %i format specifier:

printf("The sum of %i and %i is %i\n", x, y, sum);

8. Close the main function by adding a closing curly bracket:

9. Save the file as add.c .

10. Compile the program using a C compiler, for example:

gcc add.c -o add

11. Run the program using the command:

./add

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 58
01
12. The program will prompt the user to enter the x and y values and will print the
sum of x and y values.

Make sure that the CS50 library is installed on your system and that the
headers(cs50.h) are properly included in the program before compiling.

Comment [02:55:20]
In a C program, a comment is a line or block of text that is ignored by the compiler
and is not executed as part of the program. Comments are used to add notes,
explanations, and documentation to a program to make it easier for others to
understand and maintain the code.

There are two types of comments in C: single-line comments and multi-line


comments.

Single-line comments begin with the // characters and continue to the end of
the line. Anything on the right of // is considered as a comment

int main()
{
// This is a single-line comment
int x = 5; // This is also a single-line comment
//...
}

Multi-line comments begin with the /* characters and end with the /

characters, and can span multiple lines

int main()
{
/*
This is a multi-line comment
that can span
multiple lines
*/
int x = 5;
//...
}

It is a good practice to use comments to document your code, to explain what the
code is doing, and to make the code more readable. It will also help you and any
other developer who needs to read and maintain the code in the future.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 59
01
Constant [03:09:37]
A constant in C is a value that cannot be modified during the execution of a program.
Constants can be defined in several ways in C:

1. Using the #define preprocessor:

#define PI 3.14159
int main() {
double radius = 5.0;
double area = PI * radius * radius;
//...
}

This defines a symbolic constant called PI with the value 3.14159.

1. Using the const keyword:

int main() {
const double PI = 3.14159;
double radius = 5.0;
double area = PI * radius * radius;
//...
}

This defines a constant variable called PI with the value 3.14159.

1. Using the enum keyword:

enum week { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };


int main() {
enum week today;
today = Monday;
//...
}

This defines an enumeration of constant integers starting at 0.

When using constant, you should use UPPERCASE characters and separate words
with an underscore for better readability.

It is good practice to use constants instead of hardcoded values in your program, as


it makes the code more maintainable and readable. This way you only need to
change the constant in one place, and it will be reflected throughout the program.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 60
01
💠 NOTE

Constants are values that cannot be modified during the execution of


a program.

Constants can be defined in several ways in C:

Using the #define preprocessor

Using the const keyword

Using the enum keyword

When using #define preprocessor, define the constant using


UPPERCASE characters and separate words with an underscore for
better readability.

When using const keyword, the variable name should also be in


UPPERCASE characters and separate words with an underscore.

Constants defined using enum keyword, the variable name should be


in UPPERCASE characters and separate words with an underscore.

Using constants instead of hardcoded values in the program makes


the code more maintainable and readable.

A good practice is to only change the constant in one place and it will
be reflected throughout the program.

OR operator (”||’’), [03:18:36]


The "||" operator in C is a logical operator that is used to test whether either of two
expressions is true. It is called the logical OR operator because it returns true if
either of the expressions on either side of the operator is true, and false otherwise.
The operator is represented by two vertical bars (||) and is often used in conditional
statements such as "if" or "while".

Here is a simple example that demonstrates how the "||" operator can be used in a C
program:

#include <stdio.h>int main()


{
int age = 25;
int money = 500;

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 61
01
if (age >= 21 || money >= 1000) {
printf("You are allowed to enter the club.\n");
} else {
printf("You are not allowed to enter the club.\n");
}

return 0;
}

In this example, the, if statement tests whether the value of the variable "age" is
greater than or equal to 21 OR the value of the variable "money", is greater than or
equal to 1000. If either of these conditions is true, the code inside the if statement is
executed and the message "You are allowed to enter the club." is printed to the
screen. If both conditions are false, the code inside the else statement is executed
and the message "You are not allowed to enter the club." is printed to the screen.

The procedure of the above example:

1. The program starts by declaring two variables: "age" and "money".

2. Next, the, if statement is used to test whether the value of the "age" variable is
greater than or equal to 21 OR the value of the "money" variable, is greater than
or equal to 1000.

3. If either of these conditions is true, the code inside the if statement is executed,
which prints the message "You are allowed to enter the club." to the screen.

4. If both conditions are false, the code inside the else statement is executed and
the message "You are not allowed to enter the club." is printed to the screen.

5. The program then terminates and returns control to the operating system.

The "||" operator is often used in conditional statements such as "if" or "while" to test
multiple conditions at the same time. It is useful when you want to allow multiple
conditions to be true before executing a certain piece of code.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 62
01
💠 NOTE

The "||" operator in C is a logical operator that is used to test whether


either of two expressions is true.

It is called the logical OR operator because it returns true if either of


the expressions on either side of the operator is true, and false
otherwise.

The operator is represented by two vertical bars (||) and is often used
in conditional statements such as "if" or "while".

AND operator (’’&&’’)


The "&&" operator in C is a logical operator that is used to test whether both two
expressions are true. It is called the logical AND operator because it returns true if
both of the expressions on either side of the operator are true, and false otherwise.
The operator is represented by two ampersands (&&) and is often used in
conditional statements such as "if" or "while".

Here is a simple example that demonstrates how the "&&" operator can be used in a
C program:

#include <stdio.h>int main()


{
int age = 25;
int money = 500;

if (age >= 21 && money >= 1000) {


printf("You are allowed to enter the club.\n");
} else {
printf("You are not allowed to enter the club.\n");
}

return 0;
}

In this example, the, if statement tests whether the value of the variable "age" is
greater than or equal to 21 AND the value of the variable "money", is greater than or
equal to 1000. If both of these conditions are true, the code inside the if statement is
executed and the message "You are allowed to enter the club." is printed on the
screen. If either of these conditions is false, the code inside the else statement is

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 63
01
executed and the message "You are not allowed to enter the club." is printed to the
screen.

The procedure of the above example:

1. The program starts by declaring two variables: "age" and "money".

2. Next, the, if statement is used to test whether the value of the "age" variable is
greater than or equal to 21 AND the value of the "money" variable, is greater
than or equal to 1000.

3. If both conditions are true, the code inside the if statement is executed, which
prints the message "You are allowed to enter the club." to the screen.

4. If either of the conditions is false, the code inside the else statement is executed
and the message "You are not allowed to enter the club." is printed on the
screen.

5. The program then terminates and returns control to the operating system.

The "&&" operator is often used in conditional statements such as "if" or "while" to
test multiple conditions at the same time. It is useful when you want to ensure that
multiple conditions are true before executing a certain piece of code.
It is important to note that the "&&" operator has higher precedence than "||"
operator. This means when both operators appear in the same statement, the "&&"
operator will be evaluated first.

💠 NOTE

The "&&" operator in C is a logical operator that is used to test


whether both two expressions are true.

It is called the logical AND operator because it returns true if both of


the expressions on either side of the operator are true, and false
otherwise.

The operator is represented by two ampersands (&&) and is often


used in conditional statements such as "if" or "while".

while loop [03:23:06]

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 64
01
The while loop in C allows you to repeatedly execute a block of code as long as a
certain condition is true. The keyword "true" is a constant value that is always
considered to be true in a boolean context. So, when the condition "true" is used as
the loop's controlling condition, the loop will run indefinitely, until it is explicitly
terminated.

Here is an example of a while loop that runs indefinitely:

#include <stdio.h>int main()


{
int i = 0;
while (1) { // or while(true)
printf("i = %d\n", i);
i++;
}

return 0;
}

In this example, the while loop will run indefinitely, because the condition "1" or "true"
is always true. The code inside the loop increments the value of the variable "i" by 1
and prints its value to the screen on each iteration.

The procedure of the above example:

1. The program starts by declaring an integer variable "i" and initializing it with the
value 0.

2. The while loop is used with the condition "1" or "true" as the controlling condition.

3. The code inside the loop increments the value of the variable "i" by 1 and prints
its value to the screen on each iteration.

4. The loop will continue to run indefinitely until it is explicitly terminated.

It is important to note that an infinite loop like this will run forever if there is no
termination condition specified inside the loop. Therefore, it's crucial to have a
termination condition in the loop to avoid an infinite loop, as it will cause the program
to hang or crash. For example, you can use a counter variable, like i , to keep track
of how many times the loop has run, and use an if statement inside the loop to check
whether the counter has reached a certain value, and if so, use the break statement
to exit the loop.

while (1) {
printf("i = %d\n", i);
i++;

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 65
01
if(i == 10)
break;
}

In the above example, the loop will run for 10 iterations and then break out of the
loop and the program continues further.

💠 NOTE

The while loop in C allows you to repeatedly execute a block of code


as long as a certain condition is true.

The keyword "true" is a constant value that is always considered to be


true in a boolean context.

So, when the condition "true" is used as the loop's controlling


condition, the loop will run indefinitely, until it is explicitly terminated.

Example:

int i = 0;
while (1) { // or while(true)
printf("i = %d\n", i);
i++;
}

The above example, the while loop will run indefinitely, because the
condition "1" or "true" is always true.

It is important to note that an infinite loop like this will run forever if
there is no termination condition specified inside the loop.

Therefore, it's crucial to have a termination condition in the loop to


avoid an infinite loop, as it will cause the program to hang or crash.

e.g. you can use a counter variable, like i , to keep track of how many
times the loop has run, and use an if statement inside the loop to
check whether the counter has reached a certain value, and if so, use
the break statement to exit the loop.

Less than or equal to another (’’<=’’) [03:27:56]

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 66
01
In C, the "<=" operator is a comparison operator that is used to determine whether
one value is less than or equal to another. The operator is represented by the less-
than symbol (<) and the equal-to symbol (=) together ( <= ).

The "<=" operator is used to compare two values and returns a Boolean value of true
if the value on the left side of the operator is less than or equal to the value on the
right side of the operator, and false otherwise.

Here is an example of using the "<=" operator in a C program:

#include <stdio.h>int main() {


int x = 5;
int y = 7;

if (x <= y) {
printf("x is less than or equal to y.\n");
} else {
printf("x is greater than y.\n");
}

return 0;
}

In this example, the if statement tests whether the value of x is less than or equal to
the value of y. Since the value of x is 5 and the value of y is 7, x is less than y, and
the code inside the if statement is executed, which prints the message "x is less than
or equal to y." to the screen.

The "<=" operator can also be used in while loops as a controlling condition. For
example, you can use a while loop that runs while a variable is less than or equal to
a certain value.

while (i <= 10) {


printf("i = %d\n", i);
i++;
}

The above example, the while loop will run until the value of the variable i is greater
than 10

The "<=" operator is one of the basic comparison operators in C, and it is frequently
used in many programming constructs such as if-else statements, while loops, and
for loops to control the flow of the program based on the comparison results.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 67
01
for loop [03:28:58]
The for loop in C is a control flow statement that allows you to execute a block of
code multiple times. It is often used when you want to iterate over a sequence of
values, such as an array or a list.

The basic syntax of a for loop in C is as follows:

for (initialization; condition; increment/decrement) {


// code to be executed
}

The for loop has three parts:

1. The initialization: This is executed only once before the loop starts. It is used to
initialize the loop variable, often called the counter.

2. The condition: This is a Boolean expression that is evaluated before each


iteration of the loop. If the condition is true, the code inside the loop is executed,
and if the condition is false, the loop is terminated.

3. The increment/decrement: This is executed after each iteration of the loop. It is


used to update the value of the loop variable.

Here is an example of a for loop that iterates 10 times and prints the value of the
loop variable on each iteration:

#include <stdio.h>int main() {


for (int i = 0; i < 10; i++) {
printf("i = %d\n", i);
}

return 0;
}

In this example, the for loop initializes the loop variable i to 0, the condition is i<10,
and the increment is i++. The code inside the loop prints the value of i on each
iteration.
The for loop is a versatile control flow statement in C that can be used to perform a
wide variety of tasks, from simple counting to more complex operations like
traversing and manipulating data structures. It's a useful tool that allows you to
repeat a block of code a specific number of times, which makes it very powerful and
efficient.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 68
01
💠 NOTE

The for loop in C is a control flow statement that allows you to execute
a block of code multiple times.

It is often used when you want to iterate over a sequence of values,


such as an array or a list.

Syntax:

for (initialization; condition; increment/decrement) {


// code to be executed
}

The for loop has three parts:

1. Initialization: executed only once before the loop starts. It is used


to initialize the loop variable, often called the counter.

2. Condition: a Boolean expression that is evaluated before each


iteration of the loop. If the condition is true, the code inside the
loop is executed, and if the condition is false, the loop is
terminated.

3. Increment/decrement: executed after each iteration of the loop. It


is used to update the value of the loop variable.

Custom functions [03:31:58]


In C, a function is a block of code that can be called by other parts of the program to
perform a specific task. Functions can take one or more inputs (parameters) and can
return one or more outputs (return values). To create a custom function in C, you
need to follow these steps:

1. Declare the function: At the top of your C program, or in a header file, you need
to declare the function with its name, return type, and the types and names of its
parameters. The general syntax for declaring a function is as follows:

return_type function_name(parameter_type1 parameter_name1, parameter_type2 parameter_n


ame2, ...)

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 69
01
1. Define the function: After declaring the function, you need to define its body. The
definition of the function starts with the name of the function, followed by the
parameter list in parentheses, and then a block of code enclosed in curly braces.
The general syntax for defining a function is as follows:

return_type function_name(parameter_type1 parameter_name1, parameter_type2 parameter_n


ame2, ...) {
// function body
}

1. Call the function: To use a function in your C program, you need to call it by its
name, followed by the values of its parameters in parentheses. The general
syntax for calling a function is as follows:

function_name(parameter_value1, parameter_value2, ...);

Here is an example of a custom function in C that takes two integers as input and
returns their sum:

#include <stdio.h>int add(int a, int b)


{
return a + b;
}

int main() {
int x = 3;
int y = 4;
int result = add(x, y);
printf("The sum of %d and %d is %d\n", x, y, result);
return 0;
}

In this example, the function "add" is declared with a return type of int, and two
parameters of type int: "a" and "b". The function body simply returns the sum of "a"
and "b". The function is called in the main function, passing the values of x and y as
arguments. The output will be "The sum of 3 and 4 is 7".

It is important to note that in C, function prototypes are usually placed in a header


file, and the function definition is in a separate source file. This allows you to reuse
the functions in multiple source files, and separate the interface from the
implementation.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 70
01
💠 NOTE

To create a custom function in C, you need to follow these steps:

1. Declare the function: At the top of your C program, or in a header


file, you need to declare the function with its name, return type,
and the types and names of its parameters.

2. Define the function: After declaring the function, you need to


define its body.

3. Call the function: To use a function in your C program, you need to


call it by its name, followed by the values of its parameters in
parentheses.

Functions can take one or more inputs (parameters) and can return
one or more outputs (return values).

It's good practice to put the function declaration in a header file and
the definition in a separate source file. This allows you to reuse the
functions in multiple source files and separate the interface from the
implementation.

do-while loop [03:50:13]


The do-while loop in C is a control flow statement that is similar to the while loop, but
with a slight difference in the way, the loop's controlling condition is evaluated.

The basic syntax of a do-while loop in C is as follows:

do {
// code to be executed
} while (condition);

The do-while loop has two parts:

1. The code block: This is the code that will be executed repeatedly while the
condition is true.

2. The condition: This is a Boolean expression that is evaluated after each iteration
of the loop. If the condition is true, the code inside the loop is executed again,
and if the condition is false, the loop is terminated.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 71
01
The difference between the do-while loop and the while loop is that the do-while loop
guarantees that the code block will be executed at least once because the condition
is evaluated after the code block has been executed.

Here is an example of a do-while loop that prompts the user to enter a number
greater than zero and keeps prompting until the user enters a valid number:

#include <stdio.h>int main()


{
int number;
do {
printf("Enter a number greater than zero: ");
scanf("%d", &number);
} while (number <= 0);
printf("Thank you for entering a valid number!\n");
return 0;
}

In this example, the code block inside the do-while loop prompts the user to enter a
number and the condition (number <= 0) is evaluated after the input is read. If the
user enters a number less than or equal to zero, the code block is executed again
and the user is prompted to enter a valid number. This continues until the user
enters a number greater than zero, at which point the condition is false and the loop
is terminated. The final printf statement is then executed, displaying a message
thanking the user for entering a valid number.
The do-while loop is particularly useful when you need to execute a block of code at
least once before checking the condition. It's also useful when you want to keep
prompting the user for input until a valid input is received.

In summary, the do-while loop is a control flow statement in C that allows you to
execute a block of code repeatedly while a certain condition is true. The loop's
controlling condition is evaluated after each iteration, and the code block is
guaranteed to be executed at least once.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 72
01
💠 NOTE

The do-while loop in C is a control flow statement that is similar to the


while loop, but with a slight difference in the way, the loop's controlling
condition is evaluated.

Syntax:

do {
// code to be executed
} while (condition);

The do-while loop has two parts:

1. Code block: executed repeatedly while the condition is true.

2. Condition: a Boolean expression that is evaluated after each


iteration of the loop. If the condition is true, the code inside the
loop is executed again, and if the condition is false, the loop is
terminated.

The difference between the do-while loop and the while loop is that
the do-while loop guarantees that the code block will be executed at
least once because the condition is evaluated after the code block has
been executed.

do-while loop is particularly useful when:

1. you need to execute a block of code at least once before checking


the condition.

2. you want to keep prompting the user for input until a valid input is
received.

The do-while loop allows you to execute a block of code repeatedly


while a certain condition is true. The loop's controlling condition is
evaluated after each iteration, and the code block is guaranteed to be
executed at least once.

Floating-point imprecision [04:01:19]

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 73
01
Floating-point imprecision refers to the limitations of precision when working with
floating-point numbers in computer systems. Since computers use a finite number of
bits to represent floating-point numbers, they can only approximate the infinite
precision of real numbers. This can lead to errors when performing calculations with
floating-point numbers, particularly when dealing with very large or very small
numbers.

One common source of imprecision is the rounding of numbers to the nearest


representable value. For example, the number 0.1 cannot be represented exactly in
binary floating-point format, and so it must be rounded to the nearest representable
value. This can cause errors when adding or subtracting numbers that should sum to
zero.

Another source of imprecision is the limited number of significant digits. For


example, a float uses 32 bits of memory and has a precision of about 7 decimal
places, while a double uses 64 bits of memory and has a precision of about 15
decimal places.

In addition, the order of operations can also affect the precision of the result. For
example, when performing multiplications and divisions before additions and
subtractions, precision errors can accumulate quickly.
It is important to be aware of the limitations of precision when working with floating-
point numbers and to take appropriate measures to minimize imprecision errors in
your calculations. This can include using the appropriate data types for your
calculations, being mindful of the order of operations, and using libraries such as the
GNU Multiple Precision Arithmetic Library (GMP) for very precise calculations.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 74
01
💠 NOTE

Floating-point imprecision refers to limitations of precision when


working with floating-point numbers in computer systems.

Since computers use a finite number of bits to represent floating-point


numbers, they can only approximate the infinite precision of real
numbers.

Common sources of imprecision are rounding of numbers and limited


number of significant digits.

The order of operations can also affect the precision of the result.

To minimize imprecision errors, use the appropriate data types, be


mindful of the order of operations, and use libraries such as the GNU
Multiple Precision Arithmetic Library (GMP) for very precise
calculations.

Truncation [04:02:41]
Truncation in computer science refers to the process of discarding the fractional part
of a number and keeping only the integer part. Truncation is often used in computer
arithmetic to round a number down to the nearest whole number. This is also known
as "rounding towards zero."

In C, the truncation of a float to an int can be performed using the (int) typecast
operator. For example:

Copy code
float x = 3.14;
int y = (int) x;

In this example, the value of x is 3.14, but the value of y will be 3, discarding the
fractional part.

Truncation can also be performed using the floor() function from the math.h library.
For example:

Copy code
#include <math.h>float x = 3.14;

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 75
01
int y = floor(x);

In this case, the floor() function returns the largest integer that is less than or equal
to the input, in this case 3.

It's important to note that truncation can lead to a loss of precision in the final result,
particularly when working with large numbers or performing multiple arithmetic
operations. In some cases, it may be preferable to use rounding instead of
truncation.

In summary, truncation is the process of discarding the fractional part of a number


and keeping only the integer part. It can be performed in C using the typecast
operator or the floor() function. Truncation can lead to a loss of precision in the
final result and should be used with caution.

💠 NOTE

Truncation in computer science refers to the process of discarding the


fractional part of a number and keeping only the integer part.

Truncation is often used in computer arithmetic to round a number


down to the nearest whole number.

In C, truncation of a float to an int can be done using the typecast


operator or the floor() function from the math.h library.

Truncation can lead to loss of precision and care should be taken


when using this method.

Type conversion [04:03:40]


Type conversion, also known as type casting, is the process of converting a variable
from one data type to another. In C, type conversion can be performed using a
typecast operator, which is a set of parentheses that encloses the target data type.
There are two main types of type conversions: implicit and explicit.

Implicit type conversion, also known as coercion, happens automatically when an


expression of one data type is used in a context that requires a different data type.
For example, when a float is assigned to an int variable, the float will be
implicitly converted to an int .

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 76
01
Explicit type conversion, also known as a casting, is performed by the programmer
using a typecast operator. For example, the following code performs an explicit type
conversion from a float to an int :

float x = 3.14;
int y = (int) x;

Here, the float value of x is explicitly converted to an int by the (int) typecast
operator.

It's important to note that explicit type conversion can lead to a loss of precision or
range, especially when converting from a larger data type to a smaller one.
Therefore it's important to use explicit conversion judiciously.
In summary, type conversion is the process of converting a variable from one data
type to another. C provides two types of type conversion: implicit and explicit. Implicit
conversion happens automatically, while explicit conversion is performed by the
programmer using a typecast operator. It's important to use explicit conversion
judiciously, as it can lead to a loss of precision or range.

💠 NOTE

Type conversion is the process of changing a variable's data type.

It can be done implicitly or explicitly using a typecast operator in C.

Implicit conversion happens automatically.

Explicit conversion is done by the programmer.

It should be used carefully as it can cause a loss of precision or range.

Integer overflow
Integer overflow refers to a condition that occurs when a computation produces a
result that is too large to be represented within the range of values that can be
stored by the integer data type. This can happen when a computation exceeds the
maximum value that can be stored in an integer variable, resulting in a wrap-around
to a smaller value.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 77
01
For example, in C, an int data type can hold a maximum value of 2147483647. If
an operation is performed that causes the value to exceed this maximum, it will
wrap-around to the minimum value of -2147483648.

Copy code
int x = 2147483647;
x = x + 1;
printf("%d", x);

In this example, the value of x is 2147483647 before the operation, but after the
operation x = x+1 the value of x will be -2147483648.

Integer overflow can lead to unexpected results and can be a source of bugs in a
program. For example, if a program is designed to check for a maximum value and
take some action, an overflow can cause the check to fail and result in unintended
behavior.

To avoid integer overflow, it's important to use the appropriate data types for your
calculations, and to check for overflow before performing operations that can cause
it. For example, you can use the long long data type in C which can hold values up
to 9223372036854775807 and check it before performing any operation that can
cause overflow.

In summary, integer overflow refers to a condition that occurs when a computation


produces a result that is too large to be represented within the range of values that
can be stored by the integer data type. This can lead to unexpected results and bugs
in a program. To avoid integer overflow, it's important to use the appropriate data
types and check for overflow before performing operations that can cause it.

💠 NOTE

Integer overflow is a condition that occurs when a computation


exceeds the maximum value that can be stored by an integer data
type.

This can result in unexpected values or bugs in a program.

To avoid integer overflow, it's important to use the appropriate data


types and check for overflow before performing operations that can
cause it.

Introduction to Computer Science for Beginners: A Comprehensive Guide to Computer Science Fundamentals Part 78
01

You might also like