Lecture 1
Lecture 1
CONCEPTS
CS 8104
COURSE CONTENT
Programming language overview
Introduction to C Programming
General C program
Functions
PROGRAMMING LANGUAGE
OVERVIEW
What is programming language?
three groups:
PROGRAMMING LANGUAGE
OVERVIEW
Cont..
programming?
Enhanced Problem-Solving Skills
Career Competitiveness:
Cont..
oProgramming skills enable civil engineers to
FEATURES OF C LANGUAGE:
Language Compilers
Assemblers
Text Editors
Print Spoolers
APPLICATIONS OF THE
LANGUAGE
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities
GENERAL C PROGRAM
A C program generally consists of the following
components;
Preprocessor Commands
Functions
Variables
Comments
A C PROGRAM GENERALLY
CONSISTS OF THE
FOLLOWING COMPONENTS
#include <stdio.h>
int main() {
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
EXPLANATION OF THE COMPONENTS
#include <stdio.h> is a preprocessor command,
execution begins.
/*...*/ or // Statement ignored by the compiler and
following;
Data types
Variable
DATA TYPE
Specifies the type of data that a variable can
following;
Basic - int, char, float, double.
Derived
Enumeration
BASIC DATA TYPE
Integer:
Float:
places.
BASIC DATA TYPE
Char:
Typically used to hold ASCII or UTF-8 encoding
scheme characters, such as letters, numbers,
symbols, or commas.
There are 256 characters that can be
represented by a single char, which takes up
one byte of memory. Characters such as 'A',
'b', '5', or '$' are enclosed in single quotes.
BASIC DATA TYPE
Double:
Use two data types to represent two floating
integers. When additional precision is needed,
such as in scientific calculations or financial
applications, it provides greater accuracy
compared to float.
BASIC DATA TYPE
Keywords
A keyword is a reserved word.
You cannot use it as a variable name, constant
name, etc.
Examples are such as auto, break, case, char,
const, continue, default, do, double, else,
enum etc.
DECLARING AND USING
DATA TYPE IN A C
PROGRAM.
Identifier:
Is a collection of alphanumeric characters that
begins either with an alphabetical character or
an underscore, which are used to represent
various programming elements. E.g. variables,
functions, arrays, structures, unions, labels,
etc.
There are 52 alphabetical characters
(uppercase and lowercase), underscore
character, and ten numerical digits (0-9). In
DECLARING AND USING
DATA TYPE IN A C
PROGRAM.
Cont..
E.g. int myVariable;
"myVariable" is an identifier for an integer
variable.
The first letter is a lowercase letter, and the
rest of the letters are also lowercase.
DECLARING AND USING
DATA TYPE IN A C
PROGRAM.
Data types are used to declare variables or
functions with different types of data.
Examples;
int myInt;
char myChar = 'a';
float myFloat = 3.14;
double myDouble = 3.14159265359;
FORMAT SPECIFIERS
Are used to tell the compiler about the type of
data to be printed or scanned in input and
output operations.
They always start with a % symbol and are
used in the formatted string in functions like
printf(), scanf etc.
The C language provides a number of format
specifiers such as %d for int, %c for char, %f
for float, and so on.
AMPERSAND IN C
The "&" symbol is used as the address of
operator. It returns the memory location of a
variable.
Different use of Ampersand
To get the memory address of a variable.
Used in front of a variable to get its address.
The ampersand is also used to pass the
address of a variable to a function.
VARIABLE
Is a user-defined name assigned to a memory
location that holds a value that can be
modified and reused many times during the
program execution.
They store data of different types such as
integer, character, float and double.
Variable helps the compiler know what data
type to expect and which operations can be
performed.
The syntax for declaring a variable in C is as
follows:
<data type> <variable name>;
CONSTANT
Is a value that cannot be modified once it is
declared in the program.
Constants are similar to variables, but their
values remain fixed throughout the execution
of the program.
RESOURCES
Reading resource:
https://www.w3schools.com/c/index.php