0% found this document useful (0 votes)
4 views30 pages

2 - Fundamentals of Programming

The document outlines the fundamentals of programming, focusing on data types, comments, keywords, variables, constants, and operators in C programming. It explains the characteristics of signed and unsigned integers, floating-point types, and the importance of comments for code readability. Additionally, it covers various operators including increment, decrement, relational, and logical operators, and provides sample problems for practical application.
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)
4 views30 pages

2 - Fundamentals of Programming

The document outlines the fundamentals of programming, focusing on data types, comments, keywords, variables, constants, and operators in C programming. It explains the characteristics of signed and unsigned integers, floating-point types, and the importance of comments for code readability. Additionally, it covers various operators including increment, decrement, relational, and logical operators, and provides sample problems for practical application.
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/ 30

Programming

Fundamentals
Unit 2
Objectives

• enumerated different data types used in


programming;
• identified different comments;
• identified the different directives used in the
programming language;
• named variables according to the programming
language; and used constants, operators, and
expressions correctly.
Data Types
Data Types

Signed numbers use sign flag or can be distinguish between negative values and positive
values. Whereas unsigned numbers stored only positive numbers but not negative numbers.
Data Types

• Integer Data type


– The integer data type is a set of whole
numbers.
– Every integer value does not have the decimal
value.
– We use the keyword "int" to represent integer
data type in c.
Data Types
Data Types

• Floating Point data types


– Floating-point data types are a set of numbers
with the decimal value.
– The floating-point data type has two variants...
• float
• double
• We use the keyword "float" to represent floating-
point data type and "double" to represent double
data type in C.
Data Types
Data Types

• Character data type


– The character data type is a set of characters
enclosed in single quotations.
Comments and
Keywords
Comments

• The comments in C are human-readable


explanations or notes in the source code of a C
program.
• These are the statements that are not executed by
the compiler or an interpreter.
• It is a good practice to well-document our code using
comments which in turn makes our program more
readable.
Comments

When and Why to use Comments in programming?


1. A person reading a large code will be bemused if
comments are not provided about details of the program.
2. Comments are a way to make a code more readable by
providing more descriptions.
3. Comments can include a description of an algorithm to
make code understandable.
4. Comments can be used to prevent the execution of some
parts of the code.
Comments
Types of comments in C
• Single-line comments
• A single line comment in C starts with ( // ) double forward slash. It extends till the end of
the line and we do not need to specify its end.
• Example: // This is a single line comment
• Multi-line comments
• Multi line comment in C starts with a forward slash and asterisk ( /* ) and ends with an
asterisk and forward slash ( */ ).
• Example:
/*Comment starts
continues
continues
...
Comment ends*/
Keywords

• Keywords are predefined, reserved words used in programming that


have special meanings to the compiler. Keywords are part of the
syntax and they cannot be used as an identifier.
Variables and
Constant
Constant

Constant
• As the name suggests the
name constants is given to
such variables or values in C
programming language which
cannot be modified once they
are defined. They are fixed
values in a program.
Variable

• A variable in simple terms is a storage place which


has some memory allocated to it.
• Basically, a variable used to store some form of
data.
• Different types of variables require different
amounts of memory and have some specific set of
operations which can be applied to them.
Operators and
Expression
Operator
Operator

C Increment and Decrement Operators


• C programming has two operators increment ++ and
decrement -- to change the value of an operand
(constant or variable) by 1.
Operator

• An assignment
operator is used for
assigning a value to a
variable. The most
common assignment
operator is =.
Operator

C Relational Operators
• A relational operator checks the relationship
between two operands. If the relation is true, it
returns 1; if the relation is false, it returns value 0.
• Relational operators are used in decision making
and loops.
Operator
Operator

C Logical Operators
• An expression containing logical operator returns
either 0 or 1 depending upon whether expression
results true or false. Logical operators are commonly
used in decision making in C programming.
Operator
Sample Problem
Create task list, pseudocode,
IPO, Desk Check Value, Table
and Flowchart
Operator

Cayley earns $5 an hour by delivering newspapers. She


delivers newspapers 3 days each week, for 4 hours at a
time. After delivering newspapers for 8 weeks, how
much money will Cayley earn? Display the result.
Operator

Retta put $100.00 in a bank account that gains


20% interest annually. How much interest will be
accumulated in 1 year? And if she makes no
withdrawals, how much money will be in the
account after 1 year?
References

• http://www.btechsmartclass.com/c_programming/C-
Datatypes.html
• https://www.geeksforgeeks.org/c-comments/
• https://www.programiz.com/c-programming/c-
keywords-identifier
• https://www.geeksforgeeks.org/constants-vs-
variables-in-c-language/
• https://www.programiz.com/c-programming/c-
operators
Assignment

• 10/10
To be submitted in the VLE. Deadline March 3, 2023

Look for C Operator Hierarchy and explain (in your


own words) the use of operator hierarchy.

Be ready for the Quiz next week….

You might also like