SlideShare a Scribd company logo
1 of 46
CS 262
George Mason University
Department of Computer Science
Syllabus
www.hamzamughal.com
Also available on the course blackboard page
A brief introduction to C
Where?
in the Computer Science Research Department of Bell Labs in Murray Hill, NJ
Who?
by Dennis Ritchie
Why?
Previous languages (such as B) were difficult to implement programs in due to
various issues such as hardware constraints and B being incredibly slow due to it being
an interpreted language (executed by software running on top of the CPU)
C was developed to move code from assembly to a “higher” language, being
tied to the development of Unix to provide more control
https://www.bell-labs.com/usr/dmr/www/chist.pdf
ANSI (American National Standards Institute) standardized C in 1989 to create ANSI C
The International standard (ISO) was adopted by ANSI in 1990 which is known as C89
Updates in 1995 (C05) and 1999 (C99), latest being in 2018 (C18)
More on ANSI C
C is a “medium level” programming language that lets us use it at a “low level”
Contains the usual structures that many “high level” languages offer to us but also
allowing us to incorporate assembly to directly access the memory
Numerous library functions available that may be imported
Structure of a C Program
Consists of one or more functions (not methods as they are called in Java)
Program consists of executing the main function
int main (void) { … }
int main (int argc, char (argv[]) { … }
Functions contain:
A heading (data type return, name, optional arguments)
Argument declarations (if any optional arguments)
Statements (code inside the curly braces)
Preprocessors (macros, compiler controls, constant values, libraries, etc)
Additional local and external functions and variables
Recall control returns to the place where a function was called (may or may not return
with a value)
Expressions must end with a semlcolon (same as Java)
Compound instructions must be enclosed with curly braces { … }
Comments delimited by // or by multi line comments /* */
Brief intro to language processing systems
Pre processing
Compiling
Assembly
Linkage
Source Code
.i file
.s file
.o file
.exe file
Compiler Architecture
GCC
GNU Compiler Collection (aka gcc)
optimizing compiler which we will use to compile our c code
How do we utilize gcc exactly?
gcc –o hello hello.c
This command basically says compile “hello.c” to machine code name hello
“hello” is now created, now how do we run it?
./hello
Executes hello
./ is necessary (.’ specifies the directory you’re in currently)
Pitfalls
Easy to write spaghetti code since C is procedural
Preprocessors can get messy quick
Unable to gracefully terminate (meaning no catch/throw/exceptions!)
Not much of OOP
Many more which I’ve not included here…
Connecting to Zeus
Off campus?
Download the Cisco VPN https://its.gmu.edu/service/virtual-private-network-
vpn/
Connecting by SSH to Zeus via command line
ssh username@zeus.vse.gmu.edu
Download the SSH client
https://labs.vse.gmu.edu/index.php/FAQ/SSH
Copying files from/to Zeus
From your computer to Zeus
scp local user_zeus.vse.gmu.edu:~/.
From Zeus to your computer
scp user@zeus.vse.gmu.edu:~/remote local
Windows users need to use Putty
https://its.gmu.edu/knowledge-base/how-to-install-putty-ssh-for-
windows/
Shell
A command line interpreter which runs commands, programs, shell scripts
bash being the standard shell and the $ character being its default prompt
Some commands which you may utilize the most:
clear pwd ls cd cp mv rm mkdir rmdir cat
man
Vi/Vim
We will utilize vi/vim on Zeus
Text editor to create/edit files
Two modes:
Command mode and Insert Mode
Command mode to insert mode – type i
Insert mode to command mode – hit the escape key
Some commands which you may find useful:
vim filename (create a file named filename or edit existing file if it exists)
:wq (write file and exit)
:q (Quits, warning is printed if current file is not saved prior)
:q! (Quits with no warning)
:w (Save file)
Java and C Comparisons
Java runs on the JVM, provides a safe programming environment by allowing stuff
such as array bounds checks
C runs on the machine directly which does not contain such sanity checks that Java
has
Java C
Portable 1 0
Efficient 0 1
Safe 1 0
Java C
Strings String s = “Hello”; char * s = “Hello”;
char s2[6];
strcpy(s2, “Hello”)
String Concatenation s1 + s2 #include <string.h>
strcat(s1,s2)
Arrays Int [] x = new int[10]; Int x[10];
Array bounds checks Occurs at run time No run time checks
Pointers Objects are implicit pointers Int *p
Fundamentals
Variables
Consist of letters and/or digits. They should not be key words, they can’t contain
special symbols, such as blanks, -, ", etc.
A few C Keywords
typedef, return, for, char, if, goto, …
The first character must be a letter or the symbol (_)
An uppercase letter is not equivalent to a lowercase
Constants
Like variables, except their values never change
Also known as literals, need to specify the data type of the constant
Common practice to define constants in UPPER-CASE
const data_type constant_name;
Macro defined constants:
#define id value
Data Types
char – Character (1 byte)
Int – Integer (4 bytes)
float – Floating point numbers (4 bytes)
double – Floating point with double precision (8 bytes)
These data type may be coupled with the words – unsigned, signed, short, and long
before the data type
The bit size assigned to the data type usually depends on the capacity of the computer
and the compiler used. However, a char is always 1 byte.
Declarations
Conversion Types
To indicate a data type, the sign % is placed before the conversion character
printf(format string, val1, val2);
Placeholders can also specify widths and precisions
%10d : add spaces to take up at least 10 characters
%010d : add zeros to take up at least 10 characters
%.2f : print only 2 digits after decimal point
%5.2f : print 1 decimal digit, add spaces to take up 5 chars
What happens here?
Escape sequences
b Backspace
t Horizontal tab
n New line
" Quotation marks
' Apostrophe
0 Null Character
 Backward slash
Exercises
Compute the circumference and area of a circle with a given radius.
Print the ASCII value of a character
Tasks this week
Familiarize yourself with a text editor
Learn to work with Unix commands
Lab 1
Working with Zeus
“All theory and no practice makes Jack a dull boy”

More Related Content

Similar to CS262 Brief Intro to C Language

Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYRajeshkumar Reddy
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg PatelTechNGyan
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topicsveningstonk
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAlpana Gupta
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdfRajb54
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming LanguageProf Ansari
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8kapil078
 
Debug tutorial
Debug tutorialDebug tutorial
Debug tutorialDefri N
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 

Similar to CS262 Brief Intro to C Language (20)

Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
 
Basic c
Basic cBasic c
Basic c
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
C intro
C introC intro
C intro
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Debug tutorial
Debug tutorialDebug tutorial
Debug tutorial
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 

Recently uploaded

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 

CS262 Brief Intro to C Language

  • 1. CS 262 George Mason University Department of Computer Science
  • 4. Where? in the Computer Science Research Department of Bell Labs in Murray Hill, NJ Who? by Dennis Ritchie Why? Previous languages (such as B) were difficult to implement programs in due to various issues such as hardware constraints and B being incredibly slow due to it being an interpreted language (executed by software running on top of the CPU) C was developed to move code from assembly to a “higher” language, being tied to the development of Unix to provide more control https://www.bell-labs.com/usr/dmr/www/chist.pdf
  • 5.
  • 6. ANSI (American National Standards Institute) standardized C in 1989 to create ANSI C The International standard (ISO) was adopted by ANSI in 1990 which is known as C89 Updates in 1995 (C05) and 1999 (C99), latest being in 2018 (C18)
  • 7. More on ANSI C C is a “medium level” programming language that lets us use it at a “low level” Contains the usual structures that many “high level” languages offer to us but also allowing us to incorporate assembly to directly access the memory Numerous library functions available that may be imported
  • 8. Structure of a C Program
  • 9. Consists of one or more functions (not methods as they are called in Java) Program consists of executing the main function int main (void) { … } int main (int argc, char (argv[]) { … } Functions contain: A heading (data type return, name, optional arguments) Argument declarations (if any optional arguments) Statements (code inside the curly braces)
  • 10. Preprocessors (macros, compiler controls, constant values, libraries, etc) Additional local and external functions and variables Recall control returns to the place where a function was called (may or may not return with a value) Expressions must end with a semlcolon (same as Java) Compound instructions must be enclosed with curly braces { … } Comments delimited by // or by multi line comments /* */
  • 11.
  • 12.
  • 13.
  • 14. Brief intro to language processing systems
  • 17. GCC GNU Compiler Collection (aka gcc) optimizing compiler which we will use to compile our c code How do we utilize gcc exactly? gcc –o hello hello.c This command basically says compile “hello.c” to machine code name hello “hello” is now created, now how do we run it? ./hello Executes hello ./ is necessary (.’ specifies the directory you’re in currently)
  • 18. Pitfalls Easy to write spaghetti code since C is procedural Preprocessors can get messy quick Unable to gracefully terminate (meaning no catch/throw/exceptions!) Not much of OOP Many more which I’ve not included here…
  • 20. Off campus? Download the Cisco VPN https://its.gmu.edu/service/virtual-private-network- vpn/ Connecting by SSH to Zeus via command line ssh username@zeus.vse.gmu.edu Download the SSH client https://labs.vse.gmu.edu/index.php/FAQ/SSH
  • 21. Copying files from/to Zeus From your computer to Zeus scp local user_zeus.vse.gmu.edu:~/. From Zeus to your computer scp user@zeus.vse.gmu.edu:~/remote local Windows users need to use Putty https://its.gmu.edu/knowledge-base/how-to-install-putty-ssh-for- windows/
  • 22. Shell A command line interpreter which runs commands, programs, shell scripts bash being the standard shell and the $ character being its default prompt Some commands which you may utilize the most: clear pwd ls cd cp mv rm mkdir rmdir cat man
  • 24. We will utilize vi/vim on Zeus Text editor to create/edit files Two modes: Command mode and Insert Mode Command mode to insert mode – type i Insert mode to command mode – hit the escape key
  • 25. Some commands which you may find useful: vim filename (create a file named filename or edit existing file if it exists) :wq (write file and exit) :q (Quits, warning is printed if current file is not saved prior) :q! (Quits with no warning) :w (Save file)
  • 26. Java and C Comparisons
  • 27. Java runs on the JVM, provides a safe programming environment by allowing stuff such as array bounds checks C runs on the machine directly which does not contain such sanity checks that Java has
  • 28. Java C Portable 1 0 Efficient 0 1 Safe 1 0
  • 29. Java C Strings String s = “Hello”; char * s = “Hello”; char s2[6]; strcpy(s2, “Hello”) String Concatenation s1 + s2 #include <string.h> strcat(s1,s2) Arrays Int [] x = new int[10]; Int x[10]; Array bounds checks Occurs at run time No run time checks Pointers Objects are implicit pointers Int *p
  • 31. Variables Consist of letters and/or digits. They should not be key words, they can’t contain special symbols, such as blanks, -, ", etc. A few C Keywords typedef, return, for, char, if, goto, … The first character must be a letter or the symbol (_) An uppercase letter is not equivalent to a lowercase
  • 32. Constants Like variables, except their values never change Also known as literals, need to specify the data type of the constant Common practice to define constants in UPPER-CASE const data_type constant_name; Macro defined constants: #define id value
  • 33. Data Types char – Character (1 byte) Int – Integer (4 bytes) float – Floating point numbers (4 bytes) double – Floating point with double precision (8 bytes) These data type may be coupled with the words – unsigned, signed, short, and long before the data type The bit size assigned to the data type usually depends on the capacity of the computer and the compiler used. However, a char is always 1 byte.
  • 35. Conversion Types To indicate a data type, the sign % is placed before the conversion character
  • 36. printf(format string, val1, val2); Placeholders can also specify widths and precisions %10d : add spaces to take up at least 10 characters %010d : add zeros to take up at least 10 characters %.2f : print only 2 digits after decimal point %5.2f : print 1 decimal digit, add spaces to take up 5 chars
  • 37.
  • 39.
  • 40. Escape sequences b Backspace t Horizontal tab n New line " Quotation marks ' Apostrophe 0 Null Character Backward slash
  • 41.
  • 42.
  • 44. Compute the circumference and area of a circle with a given radius.
  • 45. Print the ASCII value of a character
  • 46. Tasks this week Familiarize yourself with a text editor Learn to work with Unix commands Lab 1 Working with Zeus “All theory and no practice makes Jack a dull boy”