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

03 Cintro en

Uploaded by

aryalrosn0655
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 views142 pages

03 Cintro en

Uploaded by

aryalrosn0655
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/ 142

Imperative programming

School of Technology and Management


C Language Introduction

[email protected]

ESTiG

[email protected] (ESTiG) Imperative programming 1 / 28


Summary

1 A Brief History of the C Language

2 C Language Virtues

3 Source-code and Execution

4 Identiers

5 Main Language Features

[email protected] (ESTiG) Imperative programming 2 / 28


A Brief History of the C Language

Summary

1 A Brief History of the C Language

2 C Language Virtues

3 Source-code and Execution

4 Identiers

5 Main Language Features

[email protected] (ESTiG) Imperative programming 3 / 28


A Brief History of the C Language

A Brief History of the C Language


C is a general-purpose programming language
Written in 1972 by Dennis Ritchie at Bell Labs
The name C derives from it's predecessor →
https://en.wikipedia.org/wiki/B_(programming_language)B
Language
The language grew side-by-side with the UNIX operating system
The base for most of the Linux avors today. . .
Due to it's potential, it was widely adopted by the developer
community
It's still used all over the world → General use Applications, Game
Engines, Cell-phones, O.S. Kernels, . . .

[email protected] (ESTiG) Imperative programming 4 / 28


A Brief History of the C Language

A Brief History of the C Language


C is a general-purpose programming language
Written in 1972 by Dennis Ritchie at Bell Labs
The name C derives from it's predecessor →
https://en.wikipedia.org/wiki/B_(programming_language)B
Language
The language grew side-by-side with the UNIX operating system
The base for most of the Linux avors today. . .
Due to it's potential, it was widely adopted by the developer
community
It's still used all over the world → General use Applications, Game
Engines, Cell-phones, O.S. Kernels, . . .

[email protected] (ESTiG) Imperative programming 4 / 28


A Brief History of the C Language

A Brief History of the C Language


C is a general-purpose programming language
Written in 1972 by Dennis Ritchie at Bell Labs
The name C derives from it's predecessor →
https://en.wikipedia.org/wiki/B_(programming_language)B
Language
The language grew side-by-side with the UNIX operating system
The base for most of the Linux avors today. . .
Due to it's potential, it was widely adopted by the developer
community
It's still used all over the world → General use Applications, Game
Engines, Cell-phones, O.S. Kernels, . . .

[email protected] (ESTiG) Imperative programming 4 / 28


A Brief History of the C Language

A Brief History of the C Language


C is a general-purpose programming language
Written in 1972 by Dennis Ritchie at Bell Labs
The name C derives from it's predecessor →
https://en.wikipedia.org/wiki/B_(programming_language)B
Language
The language grew side-by-side with the UNIX operating system
The base for most of the Linux avors today. . .
Due to it's potential, it was widely adopted by the developer
community
It's still used all over the world → General use Applications, Game
Engines, Cell-phones, O.S. Kernels, . . .

[email protected] (ESTiG) Imperative programming 4 / 28


A Brief History of the C Language

A Brief History of the C Language


C is a general-purpose programming language
Written in 1972 by Dennis Ritchie at Bell Labs
The name C derives from it's predecessor →
https://en.wikipedia.org/wiki/B_(programming_language)B
Language
The language grew side-by-side with the UNIX operating system
The base for most of the Linux avors today. . .
Due to it's potential, it was widely adopted by the developer
community
It's still used all over the world → General use Applications, Game
Engines, Cell-phones, O.S. Kernels, . . .

[email protected] (ESTiG) Imperative programming 4 / 28


A Brief History of the C Language

A Brief History of the C Language


C is a general-purpose programming language
Written in 1972 by Dennis Ritchie at Bell Labs
The name C derives from it's predecessor →
https://en.wikipedia.org/wiki/B_(programming_language)B
Language
The language grew side-by-side with the UNIX operating system
The base for most of the Linux avors today. . .
Due to it's potential, it was widely adopted by the developer
community
It's still used all over the world → General use Applications, Game
Engines, Cell-phones, O.S. Kernels, . . .

[email protected] (ESTiG) Imperative programming 4 / 28


A Brief History of the C Language

A Brief History of the C Language

With the advent of Object-oriented Programming, the C++


Language appears

Born from Bjarne Stroustrup's Ph.D thesis on 1979

The Object-oriented Programming is not present in the C Standard

But a common backbone is shared between the C and C++ languages


C Language characteristics are available in the C++ Language
It's important to learn C in preparation for future Course Units

[email protected] (ESTiG) Imperative programming 5 / 28


A Brief History of the C Language

A Brief History of the C Language

With the advent of Object-oriented Programming, the C++


Language appears

Born from Bjarne Stroustrup's Ph.D thesis on 1979

The Object-oriented Programming is not present in the C Standard

But a common backbone is shared between the C and C++ languages


C Language characteristics are available in the C++ Language
It's important to learn C in preparation for future Course Units

[email protected] (ESTiG) Imperative programming 5 / 28


A Brief History of the C Language

A Brief History of the C Language

With the advent of Object-oriented Programming, the C++


Language appears

Born from Bjarne Stroustrup's Ph.D thesis on 1979

The Object-oriented Programming is not present in the C Standard

But a common backbone is shared between the C and C++ languages


C Language characteristics are available in the C++ Language
It's important to learn C in preparation for future Course Units

[email protected] (ESTiG) Imperative programming 5 / 28


A Brief History of the C Language

A Brief History of the C Language

With the advent of Object-oriented Programming, the C++


Language appears

Born from Bjarne Stroustrup's Ph.D thesis on 1979

The Object-oriented Programming is not present in the C Standard

But a common backbone is shared between the C and C++ languages


C Language characteristics are available in the C++ Language
It's important to learn C in preparation for future Course Units

[email protected] (ESTiG) Imperative programming 5 / 28


A Brief History of the C Language

A Brief History of the C Language

With the advent of Object-oriented Programming, the C++


Language appears

Born from Bjarne Stroustrup's Ph.D thesis on 1979

The Object-oriented Programming is not present in the C Standard

But a common backbone is shared between the C and C++ languages


C Language characteristics are available in the C++ Language
It's important to learn C in preparation for future Course Units

C++

[email protected] (ESTiG) Imperative programming 5 / 28


A Brief History of the C Language

A Brief History of the C Language

With the advent of Object-oriented Programming, the C++


Language appears

Born from Bjarne Stroustrup's Ph.D thesis on 1979

The Object-oriented Programming is not present in the C Standard

But a common backbone is shared between the C and C++ languages


C Language characteristics are available in the C++ Language
It's important to learn C in preparation for future Course Units

C++

[email protected] (ESTiG) Imperative programming 5 / 28


C Language Virtues

Summary

1 A Brief History of the C Language

2 C Language Virtues

3 Source-code and Execution

4 Identiers

5 Main Language Features

[email protected] (ESTiG) Imperative programming 6 / 28


C Language Virtues

C Language Virtues

Some languages specic areas of intervention

C Language very versatile, no specic area of intervention


Ideal for developing any kind of application (Desktop, System, . . . )
https://en.wikipedia.org/wiki/Kernel_
Present on most
(operating_system)Operating System Kernel's (Linux, Windows, macOS)
Used in compilers and interpreters for other languages

The Java Language (i.e: the JVM) was developed in C/C++

[email protected] (ESTiG) Imperative programming 7 / 28


C Language Virtues

C Language Virtues

Some languages specic areas of intervention

C Language very versatile, no specic area of intervention


Ideal for developing any kind of application (Desktop, System, . . . )
https://en.wikipedia.org/wiki/Kernel_
Present on most
(operating_system)Operating System Kernel's (Linux, Windows, macOS)
Used in compilers and interpreters for other languages

The Java Language (i.e: the JVM) was developed in C/C++

[email protected] (ESTiG) Imperative programming 7 / 28


C Language Virtues

C Language Virtues

Some languages specic areas of intervention

C Language very versatile, no specic area of intervention


Ideal for developing any kind of application (Desktop, System, . . . )
https://en.wikipedia.org/wiki/Kernel_
Present on most
(operating_system)Operating System Kernel's (Linux, Windows, macOS)
Used in compilers and interpreters for other languages

The Java Language (i.e: the JVM) was developed in C/C++

[email protected] (ESTiG) Imperative programming 7 / 28


C Language Virtues

C Language Virtues

Some languages specic areas of intervention

C Language very versatile, no specic area of intervention


Ideal for developing any kind of application (Desktop, System, . . . )
https://en.wikipedia.org/wiki/Kernel_
Present on most
(operating_system)Operating System Kernel's (Linux, Windows, macOS)
Used in compilers and interpreters for other languages

The Java Language (i.e: the JVM) was developed in C/C++

[email protected] (ESTiG) Imperative programming 7 / 28


C Language Virtues

C Language Virtues

Some languages specic areas of intervention

C Language very versatile, no specic area of intervention


Ideal for developing any kind of application (Desktop, System, . . . )
https://en.wikipedia.org/wiki/Kernel_
Present on most
(operating_system)Operating System Kernel's (Linux, Windows, macOS)
Used in compilers and interpreters for other languages

The Java Language (i.e: the JVM) was developed in C/C++

[email protected] (ESTiG) Imperative programming 7 / 28


C Language Virtues

C Language Virtues

Some languages specic areas of intervention

C Language very versatile, no specic area of intervention


Ideal for developing any kind of application (Desktop, System, . . . )
https://en.wikipedia.org/wiki/Kernel_
Present on most
(operating_system)Operating System Kernel's (Linux, Windows, macOS)
Used in compilers and interpreters for other languages

The Java Language (i.e: the JVM) was developed in C/C++

[email protected] (ESTiG) Imperative programming 7 / 28


C Language Virtues

C Language Virtues
Due to worldwide adoption, the language is very well documented:
On independent initiatives - http://devdocs.io/cdevdocs.io,
http://en.cppreference.com/w/c/languagecppreference.com,
...
On unix-based individual man pages (ex.: man 3 printf )
As inline-documentation on IDEs (Integrated Development
Environments)1
Currently, almost every device with processing capabilities is
provided with a C compiler
This leads to a huge community of developers, contributing with:
Developer Community Support -
https://stackoverflow.com/questions/tagged/cstack overow,
https://www.reddit.com/r/C_Programming/reddit,
https://cboard.cprogramming.com/Cprogramming.com, . . .
Thousands of shared libraries of code -
https://github.com/trending?l=Cgithub.com, . . .
1 Where available. . .

[email protected] (ESTiG) Imperative programming 8 / 28


C Language Virtues

C Language Virtues
Due to worldwide adoption, the language is very well documented:
On independent initiatives - http://devdocs.io/cdevdocs.io,
http://en.cppreference.com/w/c/languagecppreference.com,
...
On unix-based individual man pages (ex.: man 3 printf )
As inline-documentation on IDEs (Integrated Development
Environments)1
Currently, almost every device with processing capabilities is
provided with a C compiler
This leads to a huge community of developers, contributing with:
Developer Community Support -
https://stackoverflow.com/questions/tagged/cstack overow,
https://www.reddit.com/r/C_Programming/reddit,
https://cboard.cprogramming.com/Cprogramming.com, . . .
Thousands of shared libraries of code -
https://github.com/trending?l=Cgithub.com, . . .
1 Where available. . .

[email protected] (ESTiG) Imperative programming 8 / 28


C Language Virtues

C Language Virtues
Due to worldwide adoption, the language is very well documented:
On independent initiatives - http://devdocs.io/cdevdocs.io,
http://en.cppreference.com/w/c/languagecppreference.com,
...
On unix-based individual man pages (ex.: man 3 printf )
As inline-documentation on IDEs (Integrated Development
Environments)1
Currently, almost every device with processing capabilities is
provided with a C compiler
This leads to a huge community of developers, contributing with:
Developer Community Support -
https://stackoverflow.com/questions/tagged/cstack overow,
https://www.reddit.com/r/C_Programming/reddit,
https://cboard.cprogramming.com/Cprogramming.com, . . .
Thousands of shared libraries of code -
https://github.com/trending?l=Cgithub.com, . . .
1 Where available. . .

[email protected] (ESTiG) Imperative programming 8 / 28


C Language Virtues

C Language Virtues
Due to worldwide adoption, the language is very well documented:
On independent initiatives - http://devdocs.io/cdevdocs.io,
http://en.cppreference.com/w/c/languagecppreference.com,
...
On unix-based individual man pages (ex.: man 3 printf )
As inline-documentation on IDEs (Integrated Development
Environments)1
Currently, almost every device with processing capabilities is
provided with a C compiler
This leads to a huge community of developers, contributing with:
Developer Community Support -
https://stackoverflow.com/questions/tagged/cstack overow,
https://www.reddit.com/r/C_Programming/reddit,
https://cboard.cprogramming.com/Cprogramming.com, . . .
Thousands of shared libraries of code -
https://github.com/trending?l=Cgithub.com, . . .
1 Where available. . .

[email protected] (ESTiG) Imperative programming 8 / 28


C Language Virtues

C Language Virtues
Due to worldwide adoption, the language is very well documented:
On independent initiatives - http://devdocs.io/cdevdocs.io,
http://en.cppreference.com/w/c/languagecppreference.com,
...
On unix-based individual man pages (ex.: man 3 printf )
As inline-documentation on IDEs (Integrated Development
Environments)1
Currently, almost every device with processing capabilities is
provided with a C compiler
This leads to a huge community of developers, contributing with:
Developer Community Support -
https://stackoverflow.com/questions/tagged/cstack overow,
https://www.reddit.com/r/C_Programming/reddit,
https://cboard.cprogramming.com/Cprogramming.com, . . .
Thousands of shared libraries of code -
https://github.com/trending?l=Cgithub.com, . . .
1 Where available. . .

[email protected] (ESTiG) Imperative programming 8 / 28


C Language Virtues

C Language Virtues
Due to worldwide adoption, the language is very well documented:
On independent initiatives - http://devdocs.io/cdevdocs.io,
http://en.cppreference.com/w/c/languagecppreference.com,
...
On unix-based individual man pages (ex.: man 3 printf )
As inline-documentation on IDEs (Integrated Development
Environments)1
Currently, almost every device with processing capabilities is
provided with a C compiler
This leads to a huge community of developers, contributing with:
Developer Community Support -
https://stackoverflow.com/questions/tagged/cstack overow,
https://www.reddit.com/r/C_Programming/reddit,
https://cboard.cprogramming.com/Cprogramming.com, . . .
Thousands of shared libraries of code -
https://github.com/trending?l=Cgithub.com, . . .
1 Where available. . .

[email protected] (ESTiG) Imperative programming 8 / 28


C Language Virtues

C Language Virtues
Due to worldwide adoption, the language is very well documented:
On independent initiatives - http://devdocs.io/cdevdocs.io,
http://en.cppreference.com/w/c/languagecppreference.com,
...
On unix-based individual man pages (ex.: man 3 printf )
As inline-documentation on IDEs (Integrated Development
Environments)1
Currently, almost every device with processing capabilities is
provided with a C compiler
This leads to a huge community of developers, contributing with:
Developer Community Support -
https://stackoverflow.com/questions/tagged/cstack overow,
https://www.reddit.com/r/C_Programming/reddit,
https://cboard.cprogramming.com/Cprogramming.com, . . .
Thousands of shared libraries of code -
https://github.com/trending?l=Cgithub.com, . . .
1 Where available. . .

[email protected] (ESTiG) Imperative programming 8 / 28


C Language Virtues

C Language Virtues
Due to worldwide adoption, the language is very well documented:
On independent initiatives - http://devdocs.io/cdevdocs.io,
http://en.cppreference.com/w/c/languagecppreference.com,
...
On unix-based individual man pages (ex.: man 3 printf )
As inline-documentation on IDEs (Integrated Development
Environments)1
Currently, almost every device with processing capabilities is
provided with a C compiler
This leads to a huge community of developers, contributing with:
Developer Community Support -
https://stackoverflow.com/questions/tagged/cstack overow,
https://www.reddit.com/r/C_Programming/reddit,
https://cboard.cprogramming.com/Cprogramming.com, . . .
Thousands of shared libraries of code -
https://github.com/trending?l=Cgithub.com, . . .
1 Where available. . .

[email protected] (ESTiG) Imperative programming 8 / 28


C Language Virtues

C Language Virtues

The language syntax (i.e.: the rules) is very simple

It includes a total of 32 reserved words


Just for reference - BASIC includes 159
Although it's a mid-level language:
The compiler can generate optimized code which can run really fast
Most of the times better than the one achieved with low-level
languages (ex.: assembly)
You can still invoke low-level routines - bit-wise operations, memory
pointer access, . . .

[email protected] (ESTiG) Imperative programming 9 / 28


C Language Virtues

C Language Virtues

The language syntax (i.e.: the rules) is very simple

It includes a total of 32 reserved words


Just for reference - BASIC includes 159
Although it's a mid-level language:
The compiler can generate optimized code which can run really fast
Most of the times better than the one achieved with low-level
languages (ex.: assembly)
You can still invoke low-level routines - bit-wise operations, memory
pointer access, . . .

[email protected] (ESTiG) Imperative programming 9 / 28


C Language Virtues

C Language Virtues

The language syntax (i.e.: the rules) is very simple

It includes a total of 32 reserved words


Just for reference - BASIC includes 159
Although it's a mid-level language:
The compiler can generate optimized code which can run really fast
Most of the times better than the one achieved with low-level
languages (ex.: assembly)
You can still invoke low-level routines - bit-wise operations, memory
pointer access, . . .

[email protected] (ESTiG) Imperative programming 9 / 28


C Language Virtues

C Language Virtues

The language syntax (i.e.: the rules) is very simple

It includes a total of 32 reserved words


Just for reference - BASIC includes 159
Although it's a mid-level language:
The compiler can generate optimized code which can run really fast
Most of the times better than the one achieved with low-level
languages (ex.: assembly)
You can still invoke low-level routines - bit-wise operations, memory
pointer access, . . .

[email protected] (ESTiG) Imperative programming 9 / 28


C Language Virtues

C Language Virtues

The language syntax (i.e.: the rules) is very simple

It includes a total of 32 reserved words


Just for reference - BASIC includes 159
Although it's a mid-level language:
The compiler can generate optimized code which can run really fast
Most of the times better than the one achieved with low-level
languages (ex.: assembly)
You can still invoke low-level routines - bit-wise operations, memory
pointer access, . . .

[email protected] (ESTiG) Imperative programming 9 / 28


C Language Virtues

C Language Virtues

The language syntax (i.e.: the rules) is very simple

It includes a total of 32 reserved words


Just for reference - BASIC includes 159
Although it's a mid-level language:
The compiler can generate optimized code which can run really fast
Most of the times better than the one achieved with low-level
languages (ex.: assembly)
You can still invoke low-level routines - bit-wise operations, memory
pointer access, . . .

[email protected] (ESTiG) Imperative programming 9 / 28


Source-code and Execution

Summary

1 A Brief History of the C Language

2 C Language Virtues

3 Source-code and Execution

4 Identiers

5 Main Language Features

[email protected] (ESTiG) Imperative programming 10 / 28


Source-code and Execution

Source-code and Execution

As in many other languages, C programming follows a workow

Although simple, it's important to understand each phase

We can describe the development loop in 4 phases:


1 Source-code review (or creation) → .c le(s)
2 Compilation (also known as building) → .o/.obj le(s)
3 Linking → .o/.obj le(s) = .exe
P
4 Execution (. . . and debugging)
5 back to 1

[email protected] (ESTiG) Imperative programming 11 / 28


Source-code and Execution

Source-code and Execution

As in many other languages, C programming follows a workow

Although simple, it's important to understand each phase

We can describe the development loop in 4 phases:


1 Source-code review (or creation) → .c le(s)
2 Compilation (also known as building) → .o/.obj le(s)
3 Linking → .o/.obj le(s) = .exe
P
4 Execution (. . . and debugging)
5 back to 1

[email protected] (ESTiG) Imperative programming 11 / 28


Source-code and Execution

Source-code and Execution

As in many other languages, C programming follows a workow

Although simple, it's important to understand each phase

We can describe the development loop in 4 phases:


1 Source-code review (or creation) → .c le(s)
2 Compilation (also known as building) → .o/.obj le(s)
3 Linking → .o/.obj le(s) = .exe
P
4 Execution (. . . and debugging)
5 back to 1

[email protected] (ESTiG) Imperative programming 11 / 28


Source-code and Execution

Source-code and Execution

As in many other languages, C programming follows a workow

Although simple, it's important to understand each phase

We can describe the development loop in 4 phases:


1 Source-code review (or creation) → .c le(s)
2 Compilation (also known as building) → .o/.obj le(s)
3 Linking → .o/.obj le(s) = .exe
P
4 Execution (. . . and debugging)
5 back to 1
// main . c
# include < stdio .h >
int main () {
printf (" Hello World !") ;
}

[email protected] (ESTiG) Imperative programming 11 / 28


Source-code and Execution

Source-code and Execution

As in many other languages, C programming follows a workow

Although simple, it's important to understand each phase

We can describe the development loop in 4 phases:


1 Source-code review (or creation) → .c le(s)
2 Compilation (also known as building) → .o/.obj le(s)
3 Linking → .o/.obj le(s) = .exe
P
4 Execution (. . . and debugging)
5 back to 1
// main . c // main . obj
# include < stdio .h > 1000 1001 0101 0010 1001
int main () { 1001 0101 0010 1000 1001
printf (" Hello World !") ; 1001 0010 1111 1100 1001
} 0010 1000 1001 1001 0101

[email protected] (ESTiG) Imperative programming 11 / 28


Source-code and Execution

Source-code and Execution

As in many other languages, C programming follows a workow

Although simple, it's important to understand each phase

We can describe the development loop in 4 phases:


1 Source-code review (or creation) → .c le(s)
2 Compilation (also known as building) → .o/.obj le(s)
3 Linking → .o/.obj le(s) = .exe
P
4 Execution (. . . and debugging)
5 back to 1
// main . c // main . obj .o .o
# include < stdio .h > 1000 1001 0101 0010 1001
int main () { 1001 0101 0010 1000 1001 exe
printf (" Hello World !") ; 1001 0010 1111 1100 1001
} 0010 1000 1001 1001 0101 .o .o

[email protected] (ESTiG) Imperative programming 11 / 28


Source-code and Execution

Source-code and Execution

As in many other languages, C programming follows a workow

Although simple, it's important to understand each phase

We can describe the development loop in 4 phases:


1 Source-code review (or creation) → .c le(s)
2 Compilation (also known as building) → .o/.obj le(s)
3 Linking → .o/.obj le(s) = .exe
P
4 Execution (. . . and debugging)
5 back to 1
// main . c // main . obj .o .o
# include < stdio .h > 1000 1001 0101 0010 1001
int main () { 1001 0101 0010 1000 1001 exe
printf (" Hello World !") ; 1001 0010 1111 1100 1001
} 0010 1000 1001 1001 0101 .o .o

[email protected] (ESTiG) Imperative programming 11 / 28


Source-code and Execution

Source-code and Execution

As in many other languages, C programming follows a workow

Although simple, it's important to understand each phase

We can describe the development loop in 4 phases:


1 Source-code review (or creation) → .c le(s)
2 Compilation (also known as building) → .o/.obj le(s)
3 Linking → .o/.obj le(s) = .exe
P
4 Execution (. . . and debugging)
5 back to 1
// main . c // main . obj .o .o
# include < stdio .h > 1000 1001 0101 0010 1001
int main () { 1001 0101 0010 1000 1001 exe
printf (" Hello World !") ; 1001 0010 1111 1100 1001
} 0010 1000 1001 1001 0101 .o .o

[email protected] (ESTiG) Imperative programming 11 / 28


Source-code and Execution

Source-code and Execution - Source-code Review

This step is the non-mechanical part in the whole development


pipeline

The programmer analyses the problem and writes the source-code


to approach it

C source les have, by convention, a .c extension


C header les have a .h extension - more on that later. . .
The sum of all .c/.h les makes up the application's source-code

These les are typically located in your local storage or in a shared


2
repository

2 Version Control System (ex.: github.com)

[email protected] (ESTiG) Imperative programming 12 / 28


Source-code and Execution

Source-code and Execution - Source-code Review

This step is the non-mechanical part in the whole development


pipeline

The programmer analyses the problem and writes the source-code


to approach it

C source les have, by convention, a .c extension


C header les have a .h extension - more on that later. . .
The sum of all .c/.h les makes up the application's source-code

These les are typically located in your local storage or in a shared


2
repository

2 Version Control System (ex.: github.com)

[email protected] (ESTiG) Imperative programming 12 / 28


Source-code and Execution

Source-code and Execution - Source-code Review

This step is the non-mechanical part in the whole development


pipeline

The programmer analyses the problem and writes the source-code


to approach it

C source les have, by convention, a .c extension


C header les have a .h extension - more on that later. . .
The sum of all .c/.h les makes up the application's source-code

These les are typically located in your local storage or in a shared


2
repository

2 Version Control System (ex.: github.com)

[email protected] (ESTiG) Imperative programming 12 / 28


Source-code and Execution

Source-code and Execution - Source-code Review

This step is the non-mechanical part in the whole development


pipeline

The programmer analyses the problem and writes the source-code


to approach it

C source les have, by convention, a .c extension


C header les have a .h extension - more on that later. . .
The sum of all .c/.h les makes up the application's source-code

These les are typically located in your local storage or in a shared


2
repository

2 Version Control System (ex.: github.com)

[email protected] (ESTiG) Imperative programming 12 / 28


Source-code and Execution

Source-code and Execution - Source-code Review

This step is the non-mechanical part in the whole development


pipeline

The programmer analyses the problem and writes the source-code


to approach it

C source les have, by convention, a .c extension


C header les have a .h extension - more on that later. . .
The sum of all .c/.h les makes up the application's source-code

These les are typically located in your local storage or in a shared


2
repository

2 Version Control System (ex.: github.com)

[email protected] (ESTiG) Imperative programming 12 / 28


Source-code and Execution

Source-code and Execution - Source-code Review

This step is the non-mechanical part in the whole development


pipeline

The programmer analyses the problem and writes the source-code


to approach it

C source les have, by convention, a .c extension


C header les have a .h extension - more on that later. . .
The sum of all .c/.h les makes up the application's source-code

These les are typically located in your local storage or in a shared


2
repository

2 Version Control System (ex.: github.com)

[email protected] (ESTiG) Imperative programming 12 / 28


Source-code and Execution

Source-code and Execution - Compilation

Once the source-code is written/reviewed you need to generate the


object-code

This is where a special translator software comes in place

The C programming language is a compiled language we use a


compiler
The compilation (i.e: translation) process:
1 Translates the instructions of your .c les
2 Generates a .o3 /.obj for each .c le

3 UNIX-based O.S.

[email protected] (ESTiG) Imperative programming 13 / 28


Source-code and Execution

Source-code and Execution - Compilation

Once the source-code is written/reviewed you need to generate the


object-code

This is where a special translator software comes in place

The C programming language is a compiled language we use a


compiler
The compilation (i.e: translation) process:
1 Translates the instructions of your .c les
2 Generates a .o3 /.obj for each .c le

3 UNIX-based O.S.

[email protected] (ESTiG) Imperative programming 13 / 28


Source-code and Execution

Source-code and Execution - Compilation

Once the source-code is written/reviewed you need to generate the


object-code

This is where a special translator software comes in place

The C programming language is a compiled language we use a


compiler
The compilation (i.e: translation) process:
1 Translates the instructions of your .c les
2 Generates a .o3 /.obj for each .c le

3 UNIX-based O.S.

[email protected] (ESTiG) Imperative programming 13 / 28


Source-code and Execution

Source-code and Execution - Compilation

Once the source-code is written/reviewed you need to generate the


object-code

This is where a special translator software comes in place

The C programming language is a compiled language we use a


compiler
The compilation (i.e: translation) process:
1 Translates the instructions of your .c les
2 Generates a .o3 /.obj for each .c le

3 UNIX-based O.S.

[email protected] (ESTiG) Imperative programming 13 / 28


Source-code and Execution

Source-code and Execution - Compilation

Once the source-code is written/reviewed you need to generate the


object-code

This is where a special translator software comes in place

The C programming language is a compiled language we use a


compiler
The compilation (i.e: translation) process:
1 Translates the instructions of your .c les
2 Generates a .o3 /.obj for each .c le

3 UNIX-based O.S.

[email protected] (ESTiG) Imperative programming 13 / 28


Source-code and Execution

Source-code and Execution - Compilation

Once the source-code is written/reviewed you need to generate the


object-code

This is where a special translator software comes in place

The C programming language is a compiled language we use a


compiler
The compilation (i.e: translation) process:
1 Translates the instructions of your .c les
2 Generates a .o3 /.obj for each .c le

3 UNIX-based O.S.

[email protected] (ESTiG) Imperative programming 13 / 28


Source-code and Execution

Source-code and Execution - Compilation


During this process, the compiler also checks for syntax errors
:::::::::::::

If you use an IDE, you get useful error information on the user
interface

[email protected] (ESTiG) Imperative programming 14 / 28


Source-code and Execution

Source-code and Execution - Compilation


During this process, the compiler also checks for syntax errors
:::::::::::::

If you use an IDE, you get useful error information on the user
interface

[email protected] (ESTiG) Imperative programming 14 / 28


Source-code and Execution

Source-code and Execution - Compilation

If you don't use an IDE (ex.: command line) you get an error in the
console

[email protected] (ESTiG) Imperative programming 15 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

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

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

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

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

// main . c
# include < stdio .h > Review Compile
int main () {
printf (" Hello World !") ;
}

errors?
:::::

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

// main . c
# include < stdio .h > Review Compile
int main () {
printf (" Hello World !") ;
}

errors?
:::::

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

// main . c
# include < stdio .h > Review Compile
int main () {
printf (" Hello World !") ;
}

errors?
:::::

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

// main . c
# include < stdio .h > Review Compile
int main () {
printf (" Hello World !") ;
}

errors?
:::::

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

// main . c
# include < stdio .h > Review Compile
int main () {
printf (" Hello World !") ;
}

errors?
:::::

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Compilation


The compiler also handles pre-processing directives:
Start with a # useful information for the compilation process
ex.: including another source le (normally header les)
You now enter the review/compile loop:
1 Source-code review/create
2 re-compile the code and check for any syntax errors
:::::::::::
3 Identify the error(s), if any goto 1
When you solve all the syntax errors the .o/.obj les are produced. . .

. . . and the process moves on to the linking phase

// main . c
# include < stdio .h > Review Compile
int main () {
printf (" Hello World !") ;
}

errors?
:::::

[email protected] (ESTiG) Imperative programming 16 / 28


Source-code and Execution

Source-code and Execution - Linking

Linking involves combining the resulting .o/.obj les into a binary


executable (.exe)
This process does not involve the programmer's intervention
Linking can be viewed as a sub-task of the compilation process
The programmer can interfere with additional compiler options to
change it's behavior, namely:
Pre-processing directives

.o .o

exe

.o .o

[email protected] (ESTiG) Imperative programming 17 / 28


Source-code and Execution

Source-code and Execution - Linking

Linking involves combining the resulting .o/.obj les into a binary


executable (.exe)
This process does not involve the programmer's intervention
Linking can be viewed as a sub-task of the compilation process
The programmer can interfere with additional compiler options to
change it's behavior, namely:
Pre-processing directives

.o .o

exe

.o .o

[email protected] (ESTiG) Imperative programming 17 / 28


Source-code and Execution

Source-code and Execution - Linking

Linking involves combining the resulting .o/.obj les into a binary


executable (.exe)
This process does not involve the programmer's intervention
Linking can be viewed as a sub-task of the compilation process
The programmer can interfere with additional compiler options to
change it's behavior, namely:
Pre-processing directives

.o .o

exe

.o .o

[email protected] (ESTiG) Imperative programming 17 / 28


Source-code and Execution

Source-code and Execution - Linking

Linking involves combining the resulting .o/.obj les into a binary


executable (.exe)
This process does not involve the programmer's intervention
Linking can be viewed as a sub-task of the compilation process
The programmer can interfere with additional compiler options to
change it's behavior, namely:
Pre-processing directives

.o .o

exe

.o .o

[email protected] (ESTiG) Imperative programming 17 / 28


Source-code and Execution

Source-code and Execution - Linking

Linking involves combining the resulting .o/.obj les into a binary


executable (.exe)
This process does not involve the programmer's intervention
Linking can be viewed as a sub-task of the compilation process
The programmer can interfere with additional compiler options to
change it's behavior, namely:
Pre-processing directives

.o .o

exe

.o .o

[email protected] (ESTiG) Imperative programming 17 / 28


Source-code and Execution

Source-code and Execution - Linking

Linking involves combining the resulting .o/.obj les into a binary


executable (.exe)
This process does not involve the programmer's intervention
Linking can be viewed as a sub-task of the compilation process
The programmer can interfere with additional compiler options to
change it's behavior, namely:
Pre-processing directives, linker options

.o .o

exe

.o .o

[email protected] (ESTiG) Imperative programming 17 / 28


Source-code and Execution

Source-code and Execution - Linking

Linking involves combining the resulting .o/.obj les into a binary


executable (.exe)
This process does not involve the programmer's intervention
Linking can be viewed as a sub-task of the compilation process
The programmer can interfere with additional compiler options to
change it's behavior, namely:
Pre-processing directives, linker options, external library locations. . .

.o .o

exe

.o .o

[email protected] (ESTiG) Imperative programming 17 / 28


Source-code and Execution

Source-code and Execution


Source-code Source-code
int main () { /* */ } int func () { /* ... */ }

[email protected] (ESTiG) Imperative programming 18 / 28


Source-code and Execution

Source-code and Execution


Source-code Source-code
int main () { /* */ } int func () { /* ... */ }

pre-processor pre-processor

[email protected] (ESTiG) Imperative programming 18 / 28


Source-code and Execution

Source-code and Execution


Source-code Source-code
int main () { /* */ } int func () { /* ... */ }

pre-processor pre-processor

C-code C-code

[email protected] (ESTiG) Imperative programming 18 / 28


Source-code and Execution

Source-code and Execution


Source-code Source-code
int main () { /* */ } int func () { /* ... */ }

pre-processor pre-processor

C-code C-code

compiler compiler

[email protected] (ESTiG) Imperative programming 18 / 28


Source-code and Execution

Source-code and Execution


Source-code Source-code
int main () { /* */ } int func () { /* ... */ }

pre-processor pre-processor

C-code C-code

compiler compiler

object-code object-code

[email protected] (ESTiG) Imperative programming 18 / 28


Source-code and Execution

Source-code and Execution


Source-code Source-code
int main () { /* */ } int func () { /* ... */ }

pre-processor pre-processor

C-code C-code

compiler compiler

object-code object-code

Linker

[email protected] (ESTiG) Imperative programming 18 / 28


Source-code and Execution

Source-code and Execution


Source-code Source-code
int main () { /* */ } int func () { /* ... */ }

pre-processor pre-processor

C-code C-code

compiler compiler

object-code object-code libraries

Linker

[email protected] (ESTiG) Imperative programming 18 / 28


Source-code and Execution

Source-code and Execution


Source-code Source-code
int main () { /* */ } int func () { /* ... */ }

pre-processor pre-processor

C-code C-code

compiler compiler

object-code object-code libraries

Linker

executable le

[email protected] (ESTiG) Imperative programming 18 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Source-code and Execution

Linking process succeeded nal working program

The program is then ready to be loaded and executed

This is done by the operating system loader:


Responsible for loading the binary le into memory
Allocating the necessary resources for it to work
Deliver it to the CPU for execution
You can still create a program that doesn't do what's supposed
to. . .

These are called Semantic Errors usually very hard to track

You normally re-enter the review/compile/execute loop to try and


solve it

[email protected] (ESTiG) Imperative programming 19 / 28


Source-code and Execution

Syntax errors vs Logic errors

To help track possible logical errors (also known as bugs) you can
use a feature called debugging

You can literally pause the program's execution by placing a


breakpoint

You then get an X-ray of the program's current status

[email protected] (ESTiG) Imperative programming 20 / 28


Source-code and Execution

Syntax errors vs Logic errors

To help track possible logical errors (also known as bugs) you can
use a feature called debugging

You can literally pause the program's execution by placing a


breakpoint

You then get an X-ray of the program's current status

[email protected] (ESTiG) Imperative programming 20 / 28


Source-code and Execution

Syntax errors vs Logic errors

To help track possible logical errors (also known as bugs) you can
use a feature called debugging

You can literally pause the program's execution by placing a


breakpoint

You then get an X-ray of the program's current status

[email protected] (ESTiG) Imperative programming 20 / 28


Identiers

Summary

1 A Brief History of the C Language

2 C Language Virtues

3 Source-code and Execution

4 Identiers

5 Main Language Features

[email protected] (ESTiG) Imperative programming 21 / 28


Identiers

Identiers

On any language you are able to name entities

On C, these names are called identiers, and are of two types:


Keywords - language reserved words, used for declaration
User-dened identiers - names given to entities such as variables,
parameters, functions, . . .
Rules for a valid identier:
Can include lowercase and uppercase letters (a-z, A-Z), digits (0-9)
and underscores (_)
The rst letter cannot be a digit (0-9)
Identiers are case-sensitive abc 6= ABC

[email protected] (ESTiG) Imperative programming 22 / 28


Identiers

Identiers

On any language you are able to name entities

On C, these names are called identiers, and are of two types:


Keywords - language reserved words, used for declaration
User-dened identiers - names given to entities such as variables,
parameters, functions, . . .
Rules for a valid identier:
Can include lowercase and uppercase letters (a-z, A-Z), digits (0-9)
and underscores (_)
The rst letter cannot be a digit (0-9)
Identiers are case-sensitive abc 6= ABC

[email protected] (ESTiG) Imperative programming 22 / 28


Identiers

Identiers

On any language you are able to name entities

On C, these names are called identiers, and are of two types:


Keywords - language reserved words, used for declaration
User-dened identiers - names given to entities such as variables,
parameters, functions, . . .
Rules for a valid identier:
Can include lowercase and uppercase letters (a-z, A-Z), digits (0-9)
and underscores (_)
The rst letter cannot be a digit (0-9)
Identiers are case-sensitive abc 6= ABC

[email protected] (ESTiG) Imperative programming 22 / 28


Identiers

Identiers

On any language you are able to name entities

On C, these names are called identiers, and are of two types:


Keywords - language reserved words, used for declaration
User-dened identiers - names given to entities such as variables,
parameters, functions, . . .
Rules for a valid identier:
Can include lowercase and uppercase letters (a-z, A-Z), digits (0-9)
and underscores (_)
The rst letter cannot be a digit (0-9)
Identiers are case-sensitive abc 6= ABC

[email protected] (ESTiG) Imperative programming 22 / 28


Identiers

Identiers

On any language you are able to name entities

On C, these names are called identiers, and are of two types:


Keywords - language reserved words, used for declaration
User-dened identiers - names given to entities such as variables,
parameters, functions, . . .
Rules for a valid identier:
Can include lowercase and uppercase letters (a-z, A-Z), digits (0-9)
and underscores (_)
The rst letter cannot be a digit (0-9)
Identiers are case-sensitive abc 6= ABC

[email protected] (ESTiG) Imperative programming 22 / 28


Identiers

Identiers

On any language you are able to name entities

On C, these names are called identiers, and are of two types:


Keywords - language reserved words, used for declaration
User-dened identiers - names given to entities such as variables,
parameters, functions, . . .
Rules for a valid identier:
Can include lowercase and uppercase letters (a-z, A-Z), digits (0-9)
and underscores (_)
The rst letter cannot be a digit (0-9)
Identiers are case-sensitive abc 6= ABC

myImportant_variable1

[email protected] (ESTiG) Imperative programming 22 / 28


Identiers

Identiers

On any language you are able to name entities

On C, these names are called identiers, and are of two types:


Keywords - language reserved words, used for declaration
User-dened identiers - names given to entities such as variables,
parameters, functions, . . .
Rules for a valid identier:
Can include lowercase and uppercase letters (a-z, A-Z), digits (0-9)
and underscores (_)
The rst letter cannot be a digit (0-9)
Identiers are case-sensitive abc 6= ABC

myImportant_variable1

[email protected] (ESTiG) Imperative programming 22 / 28


Identiers

Identiers

On any language you are able to name entities

On C, these names are called identiers, and are of two types:


Keywords - language reserved words, used for declaration
User-dened identiers - names given to entities such as variables,
parameters, functions, . . .
Rules for a valid identier:
Can include lowercase and uppercase letters (a-z, A-Z), digits (0-9)
and underscores (_)
The rst letter cannot be a digit (0-9)
Identiers are case-sensitive abc 6= ABC

myImportant_variable1

[email protected] (ESTiG) Imperative programming 22 / 28


Identiers

Identiers - Keywords

Keywords have a specic role in the language's specication

They cannot therefore be used for user-dened identiers

All C reserved words (keywords) are lower case

This is the list of 32 reserved words in the C language:

[email protected] (ESTiG) Imperative programming 23 / 28


Identiers

Identiers - Keywords

Keywords have a specic role in the language's specication

They cannot therefore be used for user-dened identiers

All C reserved words (keywords) are lower case

This is the list of 32 reserved words in the C language:

[email protected] (ESTiG) Imperative programming 23 / 28


Identiers

Identiers - Keywords

Keywords have a specic role in the language's specication

They cannot therefore be used for user-dened identiers

All C reserved words (keywords) are lower case

This is the list of 32 reserved words in the C language:

[email protected] (ESTiG) Imperative programming 23 / 28


Identiers

Identiers - Keywords

Keywords have a specic role in the language's specication

They cannot therefore be used for user-dened identiers

All C reserved words (keywords) are lower case

This is the list of 32 reserved words in the C language:

// types definition flow - control other


int typedef case sizeof
float const do volatile
char void while
double struct for
short union if
long enum else
signed switch
unsigned default
auto return
extern goto
register break
static continue

[email protected] (ESTiG) Imperative programming 23 / 28


Identiers

Identiers - Practice

1count

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count!

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count! → count!:

count1

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count! → count!:

count1 → count1

Opção

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count! → count!:

count1 → count1

Opção → Op::
ção

Option

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count! → count!:

count1 → count1

Opção → Op::
ção

Option → :: Option:


Option

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count! → count!:

count1 → count1

Opção → Op::
ção

Option → :: Option:


Option → Option

Value#

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count! → count!:

count1 → count1

Opção → Op::
ção

Option → :: Option:


Option → Option

Value# → Value::
#

value_15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count! → count!:

count1 → count1

Opção → Op::
ção

Option → :: Option:


Option → Option

Value# → Value::
#

value_15 → value_15

Value15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:

count! → count!:

count1 → count1

Opção → Op::
ção

Option → :: Option:


Option → Option

Value# → Value::
#

value_15 → value_15

Value15 → Value15

Value 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int

count! → count!:

count1 → count1

Opção → Op::
ção

Option → :: Option:


Option → Option

Value# → Value::
#

value_15 → value_15

Value15 → Value15

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int

count1 → count1

Opção → Op::
ção

Option → :: Option:


Option → Option

Value# → Value::
#

value_15 → value_15

Value15 → Value15

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer

Opção → Op::
ção

Option → :: Option:


Option → Option

Value# → Value::
#

value_15 → value_15

Value15 → Value15

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer → integer

Opção → Op::
ção 'integer'

Option → :: Option:


Option → Option

Value# → Value::
#

value_15 → value_15

Value15 → Value15

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer → integer

Opção → Op::
ção 'integer' → :
'integer:'

Option → :: Option: average-value

Option → Option

Value# → Value::
#

value_15 → value_15

Value15 → Value15

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer → integer

Opção → Op::
ção 'integer' → :
'integer:'

Option → :: Option: average-value → average-value

Option → Option average_value

Value# → Value::
#

value_15 → value_15

Value15 → Value15

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer → integer

Opção → Op::
ção 'integer' → :
'integer:'

Option → :: Option: average-value → average-value

Option → Option average_value → average_value

Value# → Value::
# average value

value_15 → value_15

Value15 → Value15

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer → integer

Opção → Op::
ção 'integer' → :
'integer:'

Option → :: Option: average-value → average-value

Option → Option average_value → average_value

Value# → Value::
# average value → average value

value_15 → value_15 averageValue

Value15 → Value15

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer → integer

Opção → Op::
ção 'integer' → :
'integer:'

Option → :: Option: average-value → average-value

Option → Option average_value → average_value

Value# → Value::
# average value → average value

value_15 → value_15 averageValue → averageValue

Value15 → Value15 bücher

Value 15 → Value: 15

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer → integer

Opção → Op::
ção 'integer' → :
'integer:'

Option → :: Option: average-value → average-value

Option → Option average_value → average_value

Value# → Value::
# average value → average value

value_15 → value_15 averageValue → averageValue

Value15 → Value15 bücher → bücher


:

Value 15 → Value: 15 case

[email protected] (ESTiG) Imperative programming 24 / 28


Identiers

Identiers - Practice

1count → 1count
:
int → int
::

count! → count!: Int → Int

count1 → count1 integer → integer

Opção → Op::
ção 'integer' → :
'integer:'

Option → :: Option: average-value → average-value

Option → Option average_value → average_value

Value# → Value::
# average value → average value

value_15 → value_15 averageValue → averageValue

Value15 → Value15 bücher → bücher


:

Value 15 → Value: 15 case → ::::


case

[email protected] (ESTiG) Imperative programming 24 / 28


Main Language Features

Summary

1 A Brief History of the C Language

2 C Language Virtues

3 Source-code and Execution

4 Identiers

5 Main Language Features

[email protected] (ESTiG) Imperative programming 25 / 28


Main Language Features

Main Language Features

Data Structures
variables, constants, data types → allow storing/processing data in
the appropriate format
Control Structures
iteration and selection that allow the programmer to change the ow
of the execution
Data Types
Describe the type of data that can be stored in a given entity
Variables
Memory resident entities that are of a given data type
Can be changed during the normal ow of the program

[email protected] (ESTiG) Imperative programming 26 / 28


Main Language Features

Main Language Features

Data Structures
variables, constants, data types → allow storing/processing data in
the appropriate format
Control Structures
iteration and selection that allow the programmer to change the ow
of the execution
Data Types
Describe the type of data that can be stored in a given entity
Variables
Memory resident entities that are of a given data type
Can be changed during the normal ow of the program

[email protected] (ESTiG) Imperative programming 26 / 28


Main Language Features

Main Language Features

Data Structures
variables, constants, data types → allow storing/processing data in
the appropriate format
Control Structures
iteration and selection that allow the programmer to change the ow
of the execution
Data Types
Describe the type of data that can be stored in a given entity
Variables
Memory resident entities that are of a given data type
Can be changed during the normal ow of the program

[email protected] (ESTiG) Imperative programming 26 / 28


Main Language Features

Main Language Features

Data Structures
variables, constants, data types → allow storing/processing data in
the appropriate format
Control Structures
iteration and selection that allow the programmer to change the ow
of the execution
Data Types
Describe the type of data that can be stored in a given entity
Variables
Memory resident entities that are of a given data type
Can be changed during the normal ow of the program

[email protected] (ESTiG) Imperative programming 26 / 28


Main Language Features

Main Language Features


Constants
Special type of variable that does not change during the whole
execution
Pointers
Special type of variable that contains a memory address
Expressions
Group of operators and operands, outlining algebraic expressions
The outcome is a value that can be stored in a variable
Instructions
Tells the computer to execute a given task
You separate instructions with a comma (;)
Structures
More complex data storing facilities that can accommodate more
than one data type
Short name in C → struct
[email protected] (ESTiG) Imperative programming 27 / 28
Main Language Features

Main Language Features


Constants
Special type of variable that does not change during the whole
execution
Pointers
Special type of variable that contains a memory address
Expressions
Group of operators and operands, outlining algebraic expressions
The outcome is a value that can be stored in a variable
Instructions
Tells the computer to execute a given task
You separate instructions with a comma (;)
Structures
More complex data storing facilities that can accommodate more
than one data type
Short name in C → struct
[email protected] (ESTiG) Imperative programming 27 / 28
Main Language Features

Main Language Features


Constants
Special type of variable that does not change during the whole
execution
Pointers
Special type of variable that contains a memory address
Expressions
Group of operators and operands, outlining algebraic expressions
The outcome is a value that can be stored in a variable
Instructions
Tells the computer to execute a given task
You separate instructions with a comma (;)
Structures
More complex data storing facilities that can accommodate more
than one data type
Short name in C → struct
[email protected] (ESTiG) Imperative programming 27 / 28
Main Language Features

Main Language Features


Constants
Special type of variable that does not change during the whole
execution
Pointers
Special type of variable that contains a memory address
Expressions
Group of operators and operands, outlining algebraic expressions
The outcome is a value that can be stored in a variable
Instructions
Tells the computer to execute a given task
You separate instructions with a comma (;)
Structures
More complex data storing facilities that can accommodate more
than one data type
Short name in C → struct
[email protected] (ESTiG) Imperative programming 27 / 28
Main Language Features

Main Language Features


Constants
Special type of variable that does not change during the whole
execution
Pointers
Special type of variable that contains a memory address
Expressions
Group of operators and operands, outlining algebraic expressions
The outcome is a value that can be stored in a variable
Instructions
Tells the computer to execute a given task
You separate instructions with a comma (;)
Structures
More complex data storing facilities that can accommodate more
than one data type
Short name in C → struct
[email protected] (ESTiG) Imperative programming 27 / 28
Main Language Features

Main Language Features

Scope/Composed expressions
Group of instructions inside a code block, outlined by {}
Example:
{
intruction1 ;
intruction2 ;
intruction3 ;
intruction4 ;
}

Also named block


Comments
Special blocks of code that have no functional meaning
// I am a single line comment
/*
I am a multi - line comment block
*/

[email protected] (ESTiG) Imperative programming 28 / 28


Main Language Features

Main Language Features

Scope/Composed expressions
Group of instructions inside a code block, outlined by {}
Example:
{
intruction1 ;
intruction2 ;
intruction3 ;
intruction4 ;
}

Also named block


Comments
Special blocks of code that have no functional meaning
// I am a single line comment
/*
I am a multi - line comment block
*/

[email protected] (ESTiG) Imperative programming 28 / 28

You might also like