際際滷

際際滷Share a Scribd company logo
Introduction to
Computer Engineering
ECSE 221




                                                       Ulhaque
                                  ECSE 221 - Muhammad Ehtasham
Muhammad Ehtasham Ulhaque
muhammad.ulhaque@mail.mcgill.ca
Tutorial 1 Winter 2011
Why use C?
 Imperative programming language
 Provides language constructs that map efficiently to machine
  instructions
 Require minimal run-time support
 Provides low-level access to memory
Difference between C & Java
 type of language                                      function oriented          object oriented
 basic programming unit                                function                   class = ADT
 portability of source code                            possible with discipline   yes
                                                       no, recompile for each     yes, bytecode is "write once,
 portability of compiled code
                                                       architecture               run anywhere"
                                                                                  public class HelloWorld {
                                                       #include<stdio.h>
                                                                                    public static void
                                                       int main(void) {
                                                                                  main(String[] args) {
                                                         printf("Hellon");
 hello, world                                                                         System.out.println("Hello")
                                                         return 0;
                                                                                  ;
                                                       }
                                                                                    }
                                                                                  }



   More to come as we go along




Source: http://www.cs.princeton.edu/introcs/faq/c2java.html
Pelles C C Compiler
   WebCT
   Download and Install Pellas C
   Set up environment
   Build a simple program  Hello World!
C  General Structure
   Libraries
   Declarations
   Method Definition
   Main Method
Data Types
   Int: Integer
   Char: One byte character
   Float: Single-precision floating point
   Double: Double-precision floating point

Array Declaration:
 Array: int array[number][number]
Example 1
//libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//declaration
#define PI 3.14

float getRadius(){
        float radius;
        printf(Please enter the radius of the circle:n);
        scanf(%f,&radius);
        return(radius);
}
Example 2 (contd.)
float getArea(float radius){
        float area;
        area = PI*radius*radius;
        return area;
}

void main()
{
      float circleradius= getRadius();
      float localarea= getArea(circleradius);
      printf("the area of a circle of radius %f is:
               %f",circleradius,localarea);
}
Basic I/O commands
 scanf: reads till a whitespace character (blank space,EOL,etc)
 Printf: outputs a line of text which can include variables
 Float and decimal types are items in a memory location thus
       Scanf(%f,&numberlocation)
       The & specifies to store the content at memory location
       numberlocation
Characters
   n :new line character
   <,>,==,!= : conditional operators
   +,-,/,* : arithmetic operators
   foo++ : use foo then increment
   ++foo: increment foo then use it
   +=,*=,/=,-=, syntax shortcut
If statements
If(<condition 1>)
        <statement block 1>
else if(<condition 2>)
        <statement block 2>
else
        <statement block 3>

EXAMPLE:
If( x==+)
         printf(the sum is %d,a+b);
else if( x==/)
         printf(the quotient is %d,a/b);
While loop
While (<condition [booleanexpression]>)
       <statement>
EXAMPLE
Int n=3;
Int number=5;
Int sum=0;
While (n>0){
       sum = sum + number;
       n--;
}
return sum;
For loop
For(<statement 1>;<condition> [booleanexpression];<statement
2>)
{
       <statement block 3>
}

EXAMPLE
sum = 0;
number = 5;
for(int n=3; n>0;n--){
        sum += number;
}
return sum;
Boolean operators
 &&: (AND)
        a && b : a and b must both be equal to 1 -> true
 ||: (OR)
        a || b : a and/or b must both be equal to 1
 ! : (NOT)
        !a return the complement of a
Bitwise operators *
   & bitwise AND
   | bitwise OR
   ^ bitwise XOR
   << left shift
   >> right shift
   A & 0x0001 -> this return the last bit
Pointers
 Data type which points to another location in memory
 int *a, b;
 a is a pointer to an integer
 b = 4;
          Location 1000 Address in byte Location 1004                 If we had
                                              4                       a 32 bit
                a                                                     machine
                                               b

            Location 1000                      Location 1004
a = &b;         1004                                 4
                  a                                    b
 *a        is the content of the location a (content at 1004) = 4
Pointers (contd.)
 a is the address which the pointer contains: 0x0002
 *a is the content of the location a (content at location
  0x0002) : 4
 &a is the address of the pointer a: 0x0001
 b is the content at pointer b: 4
 &b is the address of pointer b: 0x0002
 *b illegal operation
Command line arguments
   void main(int argc, char *argv[])
   argc
   Integers which is equal to the number of terms in the call
   argv
   Array of pointers

More Related Content

What's hot (20)

C++ Chapter I
C++ Chapter IC++ Chapter I
C++ Chapter I
Sorn Chanratha
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
Carson Wilber
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
Modern C++
Modern C++Modern C++
Modern C++
Michael Clark
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
rohassanie
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
CyberPlusIndia
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizationsEgor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov
C++ Chapter IV
C++ Chapter IVC++ Chapter IV
C++ Chapter IV
Sorn Chanratha
C++11
C++11C++11
C++11
ppd1961
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Meghaj Mallick
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
Dr. Md. Shohel Sayeed
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
Mihai Todor
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
go-lang
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
Markus Schneider
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
archikabhatia
C++ Chapter III
C++ Chapter IIIC++ Chapter III
C++ Chapter III
Sorn Chanratha
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
Dr. Md. Shohel Sayeed
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
Jan R端egg
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
fawzmasood
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
rohassanie
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizationsEgor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov
C++11
C++11C++11
C++11
ppd1961
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Meghaj Mallick
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
Mihai Todor
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
go-lang
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
Markus Schneider
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
archikabhatia
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
Jan R端egg
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
fawzmasood

Similar to ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtasham Ulhaque (20)

C# - What's next
C# - What's nextC# - What's next
C# - What's next
Christian Nagel
C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...
nadeemsk351
C
CC
C
Jerin John
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
Christian Nagel
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
SandipPradhan23
CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
Jay Patel
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
AmIt Prasad
C# for Java Developers
C# for Java DevelopersC# for Java Developers
C# for Java Developers
Jussi Pohjolainen
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptx
Ian Robertson
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
Koteswari Kasireddy
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
Apache Thrift
Apache ThriftApache Thrift
Apache Thrift
knight1128
redev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
redev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...redev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
redev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Charles Nutter
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
Kevin Pilch
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centre
jatin batra
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
heinrich.wendel
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
Abdullah Jan
C# - What's Next?
C# - What's Next?C# - What's Next?
C# - What's Next?
Christian Nagel
C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...
nadeemsk351
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
Christian Nagel
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
SandipPradhan23
CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
Jay Patel
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
AmIt Prasad
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptx
Ian Robertson
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
Apache Thrift
Apache ThriftApache Thrift
Apache Thrift
knight1128
redev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
redev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...redev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
redev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Charles Nutter
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
Kevin Pilch
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centre
jatin batra
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
Abdullah Jan

Recently uploaded (20)

Unit No 4- Chemotherapy of Malignancy.pptx
Unit No  4- Chemotherapy of Malignancy.pptxUnit No  4- Chemotherapy of Malignancy.pptx
Unit No 4- Chemotherapy of Malignancy.pptx
Ashish Umale
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT PPT.pptx
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT PPT.pptxANORECTAL MALFORMATIONS: NURSING MANAGEMENT PPT.pptx
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT PPT.pptx
PRADEEP ABOTHU
Introduction to Systematic Reviews - Prof Ejaz Khan
Introduction to Systematic Reviews - Prof Ejaz KhanIntroduction to Systematic Reviews - Prof Ejaz Khan
Introduction to Systematic Reviews - Prof Ejaz Khan
Systematic Reviews Network (SRN)
How to Manage Check Out Process in Odoo 17 Website
How to Manage Check Out Process in Odoo 17 WebsiteHow to Manage Check Out Process in Odoo 17 Website
How to Manage Check Out Process in Odoo 17 Website
Celine George
10.socialorganisationandsocialsystem .pptx
10.socialorganisationandsocialsystem .pptx10.socialorganisationandsocialsystem .pptx
10.socialorganisationandsocialsystem .pptx
Vivek Bhattji
Knownsense 2025 Finals-U-25 General Quiz.pdf
Knownsense 2025 Finals-U-25 General Quiz.pdfKnownsense 2025 Finals-U-25 General Quiz.pdf
Knownsense 2025 Finals-U-25 General Quiz.pdf
Pragya - UEM Kolkata Quiz Club
O SWEET SPONTANEOUS BY EDWARD ESTLIN CUMMINGSAN.pptx
O SWEET SPONTANEOUS BY EDWARD ESTLIN CUMMINGSAN.pptxO SWEET SPONTANEOUS BY EDWARD ESTLIN CUMMINGSAN.pptx
O SWEET SPONTANEOUS BY EDWARD ESTLIN CUMMINGSAN.pptx
AituzazKoree
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptx
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptxCLEFT LIP AND PALATE: NURSING MANAGEMENT.pptx
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
UNIT 1 Introduction to communication.pptx
UNIT 1 Introduction to communication.pptxUNIT 1 Introduction to communication.pptx
UNIT 1 Introduction to communication.pptx
HARIHARAN A
Analysis of Conf File Parameters in Odoo 17
Analysis of Conf File Parameters in Odoo 17Analysis of Conf File Parameters in Odoo 17
Analysis of Conf File Parameters in Odoo 17
Celine George
MIPLM subject matter expert Dr Robert Klinski
MIPLM subject matter expert Dr Robert KlinskiMIPLM subject matter expert Dr Robert Klinski
MIPLM subject matter expert Dr Robert Klinski
MIPLM
Managing Online Signature and Payment with Odoo 17
Managing Online Signature and Payment with Odoo 17Managing Online Signature and Payment with Odoo 17
Managing Online Signature and Payment with Odoo 17
Celine George
How to Install Odoo 18 with Pycharm - Odoo 18 際際滷s
How to Install Odoo 18 with Pycharm - Odoo 18 際際滷sHow to Install Odoo 18 with Pycharm - Odoo 18 際際滷s
How to Install Odoo 18 with Pycharm - Odoo 18 際際滷s
Celine George
Quizzitch Cup_Sports Quiz 2025_Prelims.pptx
Quizzitch Cup_Sports Quiz 2025_Prelims.pptxQuizzitch Cup_Sports Quiz 2025_Prelims.pptx
Quizzitch Cup_Sports Quiz 2025_Prelims.pptx
Anand Kumar
Strategic Corporate Social Responsibility: Sustainable Value Creation Fourth
Strategic Corporate Social Responsibility: Sustainable Value Creation FourthStrategic Corporate Social Responsibility: Sustainable Value Creation Fourth
Strategic Corporate Social Responsibility: Sustainable Value Creation Fourth
keileyrazawi
General Quiz at Maharaja Agrasen College | Amlan Sarkar | Prelims with Answer...
General Quiz at Maharaja Agrasen College | Amlan Sarkar | Prelims with Answer...General Quiz at Maharaja Agrasen College | Amlan Sarkar | Prelims with Answer...
General Quiz at Maharaja Agrasen College | Amlan Sarkar | Prelims with Answer...
Amlan Sarkar
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
home
3. AI Trust Layer, Governance Explainability, Security & Compliance.pdf
3. AI Trust Layer, Governance  Explainability, Security & Compliance.pdf3. AI Trust Layer, Governance  Explainability, Security & Compliance.pdf
3. AI Trust Layer, Governance Explainability, Security & Compliance.pdf
Mukesh Kala
Marketing is Everything in the Beauty Business! 憓 Talent gets you in the ...
 Marketing is Everything in the Beauty Business! 憓 Talent gets you in the ... Marketing is Everything in the Beauty Business! 憓 Talent gets you in the ...
Marketing is Everything in the Beauty Business! 憓 Talent gets you in the ...
coreylewis960
Different Facets of Knowledge on different View.pptx
Different Facets of Knowledge on different View.pptxDifferent Facets of Knowledge on different View.pptx
Different Facets of Knowledge on different View.pptx
NrapendraVirSingh
Unit No 4- Chemotherapy of Malignancy.pptx
Unit No  4- Chemotherapy of Malignancy.pptxUnit No  4- Chemotherapy of Malignancy.pptx
Unit No 4- Chemotherapy of Malignancy.pptx
Ashish Umale
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT PPT.pptx
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT PPT.pptxANORECTAL MALFORMATIONS: NURSING MANAGEMENT PPT.pptx
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT PPT.pptx
PRADEEP ABOTHU
How to Manage Check Out Process in Odoo 17 Website
How to Manage Check Out Process in Odoo 17 WebsiteHow to Manage Check Out Process in Odoo 17 Website
How to Manage Check Out Process in Odoo 17 Website
Celine George
10.socialorganisationandsocialsystem .pptx
10.socialorganisationandsocialsystem .pptx10.socialorganisationandsocialsystem .pptx
10.socialorganisationandsocialsystem .pptx
Vivek Bhattji
O SWEET SPONTANEOUS BY EDWARD ESTLIN CUMMINGSAN.pptx
O SWEET SPONTANEOUS BY EDWARD ESTLIN CUMMINGSAN.pptxO SWEET SPONTANEOUS BY EDWARD ESTLIN CUMMINGSAN.pptx
O SWEET SPONTANEOUS BY EDWARD ESTLIN CUMMINGSAN.pptx
AituzazKoree
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptx
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptxCLEFT LIP AND PALATE: NURSING MANAGEMENT.pptx
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
UNIT 1 Introduction to communication.pptx
UNIT 1 Introduction to communication.pptxUNIT 1 Introduction to communication.pptx
UNIT 1 Introduction to communication.pptx
HARIHARAN A
Analysis of Conf File Parameters in Odoo 17
Analysis of Conf File Parameters in Odoo 17Analysis of Conf File Parameters in Odoo 17
Analysis of Conf File Parameters in Odoo 17
Celine George
MIPLM subject matter expert Dr Robert Klinski
MIPLM subject matter expert Dr Robert KlinskiMIPLM subject matter expert Dr Robert Klinski
MIPLM subject matter expert Dr Robert Klinski
MIPLM
Managing Online Signature and Payment with Odoo 17
Managing Online Signature and Payment with Odoo 17Managing Online Signature and Payment with Odoo 17
Managing Online Signature and Payment with Odoo 17
Celine George
How to Install Odoo 18 with Pycharm - Odoo 18 際際滷s
How to Install Odoo 18 with Pycharm - Odoo 18 際際滷sHow to Install Odoo 18 with Pycharm - Odoo 18 際際滷s
How to Install Odoo 18 with Pycharm - Odoo 18 際際滷s
Celine George
Quizzitch Cup_Sports Quiz 2025_Prelims.pptx
Quizzitch Cup_Sports Quiz 2025_Prelims.pptxQuizzitch Cup_Sports Quiz 2025_Prelims.pptx
Quizzitch Cup_Sports Quiz 2025_Prelims.pptx
Anand Kumar
Strategic Corporate Social Responsibility: Sustainable Value Creation Fourth
Strategic Corporate Social Responsibility: Sustainable Value Creation FourthStrategic Corporate Social Responsibility: Sustainable Value Creation Fourth
Strategic Corporate Social Responsibility: Sustainable Value Creation Fourth
keileyrazawi
General Quiz at Maharaja Agrasen College | Amlan Sarkar | Prelims with Answer...
General Quiz at Maharaja Agrasen College | Amlan Sarkar | Prelims with Answer...General Quiz at Maharaja Agrasen College | Amlan Sarkar | Prelims with Answer...
General Quiz at Maharaja Agrasen College | Amlan Sarkar | Prelims with Answer...
Amlan Sarkar
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
home
3. AI Trust Layer, Governance Explainability, Security & Compliance.pdf
3. AI Trust Layer, Governance  Explainability, Security & Compliance.pdf3. AI Trust Layer, Governance  Explainability, Security & Compliance.pdf
3. AI Trust Layer, Governance Explainability, Security & Compliance.pdf
Mukesh Kala
Marketing is Everything in the Beauty Business! 憓 Talent gets you in the ...
 Marketing is Everything in the Beauty Business! 憓 Talent gets you in the ... Marketing is Everything in the Beauty Business! 憓 Talent gets you in the ...
Marketing is Everything in the Beauty Business! 憓 Talent gets you in the ...
coreylewis960
Different Facets of Knowledge on different View.pptx
Different Facets of Knowledge on different View.pptxDifferent Facets of Knowledge on different View.pptx
Different Facets of Knowledge on different View.pptx
NrapendraVirSingh

ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtasham Ulhaque

  • 1. Introduction to Computer Engineering ECSE 221 Ulhaque ECSE 221 - Muhammad Ehtasham Muhammad Ehtasham Ulhaque muhammad.ulhaque@mail.mcgill.ca Tutorial 1 Winter 2011
  • 2. Why use C? Imperative programming language Provides language constructs that map efficiently to machine instructions Require minimal run-time support Provides low-level access to memory
  • 3. Difference between C & Java type of language function oriented object oriented basic programming unit function class = ADT portability of source code possible with discipline yes no, recompile for each yes, bytecode is "write once, portability of compiled code architecture run anywhere" public class HelloWorld { #include<stdio.h> public static void int main(void) { main(String[] args) { printf("Hellon"); hello, world System.out.println("Hello") return 0; ; } } } More to come as we go along Source: http://www.cs.princeton.edu/introcs/faq/c2java.html
  • 4. Pelles C C Compiler WebCT Download and Install Pellas C Set up environment Build a simple program Hello World!
  • 5. C General Structure Libraries Declarations Method Definition Main Method
  • 6. Data Types Int: Integer Char: One byte character Float: Single-precision floating point Double: Double-precision floating point Array Declaration: Array: int array[number][number]
  • 7. Example 1 //libraries #include <stdio.h> #include <stdlib.h> #include <string.h> //declaration #define PI 3.14 float getRadius(){ float radius; printf(Please enter the radius of the circle:n); scanf(%f,&radius); return(radius); }
  • 8. Example 2 (contd.) float getArea(float radius){ float area; area = PI*radius*radius; return area; } void main() { float circleradius= getRadius(); float localarea= getArea(circleradius); printf("the area of a circle of radius %f is: %f",circleradius,localarea); }
  • 9. Basic I/O commands scanf: reads till a whitespace character (blank space,EOL,etc) Printf: outputs a line of text which can include variables Float and decimal types are items in a memory location thus Scanf(%f,&numberlocation) The & specifies to store the content at memory location numberlocation
  • 10. Characters n :new line character <,>,==,!= : conditional operators +,-,/,* : arithmetic operators foo++ : use foo then increment ++foo: increment foo then use it +=,*=,/=,-=, syntax shortcut
  • 11. If statements If(<condition 1>) <statement block 1> else if(<condition 2>) <statement block 2> else <statement block 3> EXAMPLE: If( x==+) printf(the sum is %d,a+b); else if( x==/) printf(the quotient is %d,a/b);
  • 12. While loop While (<condition [booleanexpression]>) <statement> EXAMPLE Int n=3; Int number=5; Int sum=0; While (n>0){ sum = sum + number; n--; } return sum;
  • 13. For loop For(<statement 1>;<condition> [booleanexpression];<statement 2>) { <statement block 3> } EXAMPLE sum = 0; number = 5; for(int n=3; n>0;n--){ sum += number; } return sum;
  • 14. Boolean operators &&: (AND) a && b : a and b must both be equal to 1 -> true ||: (OR) a || b : a and/or b must both be equal to 1 ! : (NOT) !a return the complement of a
  • 15. Bitwise operators * & bitwise AND | bitwise OR ^ bitwise XOR << left shift >> right shift A & 0x0001 -> this return the last bit
  • 16. Pointers Data type which points to another location in memory int *a, b; a is a pointer to an integer b = 4; Location 1000 Address in byte Location 1004 If we had 4 a 32 bit a machine b Location 1000 Location 1004 a = &b; 1004 4 a b *a is the content of the location a (content at 1004) = 4
  • 17. Pointers (contd.) a is the address which the pointer contains: 0x0002 *a is the content of the location a (content at location 0x0002) : 4 &a is the address of the pointer a: 0x0001 b is the content at pointer b: 4 &b is the address of pointer b: 0x0002 *b illegal operation
  • 18. Command line arguments void main(int argc, char *argv[]) argc Integers which is equal to the number of terms in the call argv Array of pointers