SlideShare ist ein Scribd-Unternehmen logo
1 von 40
C
a series of presentations to help a bunch of
   brilliant space scientists understand a
       brilliant programming language
Why?


You wrote a really complex C program called


     super_complex_no_idea_what_i_justwrote.c
Why?

              You use gcc to
              compile it . . .


$ gcc super_complex_no_idea_what_i_justwrote.c
Why?



compiling . . .
Why?



no errors. . .
Why?



$./a.out
Segmentation Fault
$
Why?
• Discovered a piece of C code in a book or the internet that solves your
problem

• Copied it into your program and somehow made it compile

• No testing whatsoever

• Program runs and gives you right output for your small set of conveniently
selected input

• Job done. Decided to comment your code later. Forgotten all about it.

• Three months later someone comes and tells you to change your code for
another input or someone comes and tells you that your code is not working.

• Open your source code and stare at it ….. trying to make sense of what you
did

• Delete everything and go back to search a book or the internet to solve
your problem
hello world
#include <stdio.h>

int main(void)
{                                text file named hello.c
      printf(“Hello Worldn”);
      return 0;
}



$ gcc hello.c                      compile


$ a.out
Hello World                        execute
$
Lets analyze it in detail . . . .
a simple C program
                                 Instructs the preprocessor to
#include <stdio.h>               add the contents of the header
                                 file stdio.h into hello.c
int main(void)
                                                       next line
{
      printf(“Hello Worldn”);
      return 0;
}
a simple C program
                                     Instructs the preprocessor to
#include <stdio.h>                   add the contents of the header
                                     file stdio.h into hello.c
int main(void)
{
      printf(“Hello Worldn”);
      return 0;
}
                             Why does ‘stdio.h ‘have
                             angle brackets <>?
   What is # include ?


                         What is stdio.h?
                         Where is it stored?
a simple C program
#include <stdio.h>                                 Pre processor
int main(void)
                                                   directive
{
      printf(“Hello Worldn”);
      return 0;
}
• Instructions meant for the pre-processor

• Always being with a ‘#’ symbol

• #include puts every line in the file stdio.h into hello.c

• Other pre processor directive examples: #define, #ifdef
#pragma, etc.
a simple C program
#include <stdio.h>                                 Pre processor
int main(void)
                                                   directive
{
      printf(“Hello Worldn”);
      return 0;
}
• < angle brackets > tells the #include directive to search for the file
stdio.h in the standard C header file location.

• The default standard C header files in a Unix machine is
  /usr/header,

• We can use “ ” instead of < > to tell the include directive to first
search for the file in the same directory as your C file, then the
standard .
a simple C program
#include <stdio.h>                                 Standard C headers
int main(void)
{
      printf(“Hello Worldn”);
      return 0;
}
• A file ending with ‘.h’ is known as a C header file.

• A set of header files are available by default with the C
programming language. These are known as standard C headers

• The standard C headers contains declarations of system functions
that allows you to invoke system calls and system libraries
a simple C program
#include <stdio.h>                               Standard C headers
int main(void)
{
      printf(“Hello Worldn”);
      return 0;
}
• stdio.h is one of the standard C headers that defines all standard
input and output functions

• In this program, we have an output function printf which is
declared in stdio.h

• stdio.h location is /usr/header/stdio.h
a simple C program
#include <stdio.h>
                                 main is the first function called
int main(void)                   when you execute your
{                                program.
      printf(“Hello Worldn”);                           next line
      return 0;
}
a simple C program
#include <stdio.h>
                                      main is the first function called
int main(void)                        when you execute your
{                                     program.
      printf(“Hello Worldn”);                                next line
      return 0;
}



    What is int main(void)?              Who calls main() function?


                  Who decided the name ‘main()’?
                    Why can’t I write my own
                       function ‘start()’ ?
a simple C program
#include <stdio.h>

int main(void)
                                                          Main function
{
      printf(“Hello Worldn”);
      return 0;
}
• Functions are a set of C instructions enclosed under a particular name. Eg:
                                    function
                                      name
              return type   int     add(int a, int b) parameters
                            {
                                  int sum; instructions
                                  sum = a + b;
                                  return sum;
                            }

• Functions make our code readable
a simple C program
#include <stdio.h>

int main(void)
                                                     Main function
{
      printf(“Hello Worldn”);
      return 0;
}
•main() is a special function that is first called when a C program is executed. Every C
program must have only one main() function to execute.

• int main( void ) tells us that the main() function takes no parameters as input and
returns an integer as output

•The main function is called by runtime environment of an operating system (Eg: in
Unix, the program is executed by the shell interpreter. )
a simple C program
#include <stdio.h>

int main(void)
                                                   C Standard 99
{
      printf(“Hello Worldn”);
      return 0;
}

• C Standard 99 – is one of the many standards that put forward rules on how C
programming language should be designed on different platforms (like
Unix, Windows. Solaris, etc). This ensures a common functionality on all platforms

• C Standard 99 – an ISO defined standard states that a C program should have the any
one of the two main() function definitions int main(void)

                                           int main(int argc, char* argv[])
a simple C program
#include <stdio.h>

int main(void)
{                                printf function prints the
      printf(“Hello Worldn”);   characters “Hello World ”
      return 0;                  to the standard output
}                                stream.
                                                        next line
a simple C program
#include <stdio.h>

int main(void)
{                                   printf function prints the
      printf(“Hello Worldn”);      characters “Hello World ”
      return 0;                     to the standard output.
}



                     What do you mean
                     by ‘standard output
                           stream’?
a simple C program
#include <stdio.h>
                                                     Standard Streams
int main(void)
{
      printf(“Hello Worldn”);
      return 0;
}

• Standard output in C language is defined as the output to the terminal screen. ( in
Unix, it is the shell window where the program was executed)

• Along with standard output stream, C defines the standard input stream (keyboard)
and standard error stream(screen again)

• These are also defined in stdio.h as per C Standard 99 definitions
a simple C program
#include <stdio.h>

int main(void)
{
      printf(“Hello Worldn”);
      return 0;                  return the value 0.
}
a simple C program
#include <stdio.h>

int main(void)
{
      printf(“Hello Worldn”);
      return 0;                  return the value 0.
}


                               Who did we
                             just send ‘0’ to?
          Why are we
         returning ‘0’ ?
a simple C program
#include <stdio.h>

int main(void)
{
      printf(“Hello Worldn”);
      return 0;                                       End of program
}

• The last line of main() function has a return 0; line where 0 is defined as a successful
execution in C Standard 99.

• It tells the runtime environment that the C program successfully executed all its
lines of code.

• The significance of this return value arises when the runtime environment executes
multiple C programs. It helps it keep track of how many programs successfully
executed.
compile
                          Run a program named
                          gcc to compile the file
                          hello.c
$ gcc hello.c             Notice that another
                          file called a.out
                          is created in the
                          same folder
compile
                                            Run a program named
                                            gcc to compile the file
                                            hello.c
$ gcc hello.c                               Notice that another
                                            file called a.out
                                            is created in the
                                            same folder
  What exactly do
   you mean by
     ‘compile’?
                                       What is gcc ?



                 Whats inside my
                executable ‘a.out’ ?
compile

 $ gcc hello.c                                                 Compile
• The process of converting a high level language (such as C language) instructions to a
low level language (such as machine language 1’s and 0’s) instructions

• Strictly speaking, the process of compiling does not yield an executable file… It is
only one of the many steps involved in creating it.
compile

$ gcc hello.c                                                What really
    Preprocessor (gcc)         preprocessor to expand
                                                             happens is…
                               macros and includes header
                     hello.i   files

     Compiler (gcc)            actual compilation of
                               preprocessed source code
                     hello.s   to assembly language

     Assembler (as)            convert assembly language
                               into machine code and
                               generate an object file
                     hello.o

       Linker (ld)             linking of object file with
                               C run time libraries to
                               create an executable
        a.out
compile

                                                             GNU Compiler
 $ gcc hello.c
                                                             Collection
                                                             (GCC)
• This is a compiler system that is produced by the GNU (GNU Not Unix) Project.

• Originally named GNU C Compiler, later changed after the inclusion of languages like
C++, Ada, Fortran, Lisp, Java, Objective-C, Go, and many more.

• Its open source!!

• Website: http://gcc.gnu.org
compile

 $ gcc hello.c                                                a.out
• The executable that is the available after the entire compilation and linking process

• Its all 1’s and 0’s (binary) which only the machine can understand… you definitely
cannot

• All executables that are generated are always named a.out by default (can be
overridden with the –o flag in gcc )

• ‘a.out’ name comes from a really old file format for executable files. Nowadays all
executable files follow the ELF (Executable and Linkable Format)
execute
$ a.out                 Run a.out and see
Hello World             the line “Hello World”
$                       on the screen.
execute
$ a.out                          Run a.out and see
Hello World                      the line “Hello World”
$                                on the screen.




              Wow!! That looked easy
              How did it all happen?
execute
$ a.out                                                     From Executable
Hello World
$                                                           to a Process

               pid
              22134
  Memory                       Operating                  a.out   Hard
              starting
                                System                            Disk
              address
        CPU


• a.out file is loaded by the operating system to memory (RAM) as an executing
process.

• Each process gets a unique id called process id (pid)
execute
$ a.out                                       Memory Layout
Hello World                                   of your C program
$
 Command line
 arguments, Environment
 variables
 Stack Segment
                                  Now you know where the
                                  ‘segment’ in segmentation
                                  fault comes from 

 Heap Segment
 BSS Segment
 Initialized Data Segment

 Text Segment                Memory Region
… and that’s how it works
what next?
  File I/O                      Data types
                Standard       & structures
                C Library

     Pointers & Memory
          Allocation          Debugging


 Macro and                      Version
Pre Processor                 Management

                 Multi file
                 projects
the creator of C…




  Dennis Ritchie
  9th Sept 1941 – 12th Oct 2011
Choose a job you love,
and you will never have to work a day in your life
                   - Confucious




                           thank you

Weitere ähnliche Inhalte

Was ist angesagt?

4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1Little Tukta Lita
 
UNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CUNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CRaj vardhan
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointersMomenMostafa
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structuresindra Kishor
 
Implementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & CImplementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & CEleanor McHugh
 
C Prog - Functions
C Prog - FunctionsC Prog - Functions
C Prog - Functionsvinay arora
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and coweltling
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string libraryMomenMostafa
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Deepak Singh
 
Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3MOHIT TOMAR
 
C language header files
C language header filesC language header files
C language header filesmarar hina
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : PythonOpen Gurukul
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13Chris Ohk
 
C ISRO Debugging
C ISRO DebuggingC ISRO Debugging
C ISRO Debuggingsplix757
 

Was ist angesagt? (20)

4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
 
UNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN CUNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN C
 
C++ programming
C++ programmingC++ programming
C++ programming
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structures
 
Implementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & CImplementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & C
 
C Prog - Functions
C Prog - FunctionsC Prog - Functions
C Prog - Functions
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and co
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009
 
Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3
 
C language header files
C language header filesC language header files
C language header files
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
 
basics of c++
basics of c++basics of c++
basics of c++
 
mpi4py.pdf
mpi4py.pdfmpi4py.pdf
mpi4py.pdf
 
C ISRO Debugging
C ISRO DebuggingC ISRO Debugging
C ISRO Debugging
 

Ähnlich wie C - ISRO

5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.Fiaz Hussain
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg PatelTechNGyan
 
Sachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin Kumar
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfssuser33f16f
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and typesimtiazalijoono
 
C programming on Ubuntu
C programming on UbuntuC programming on Ubuntu
C programming on UbuntuBinu Joy
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005Saleem Ansari
 
Introduction to c language by nitesh
Introduction to c language by niteshIntroduction to c language by nitesh
Introduction to c language by niteshniteshcongreja321
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib웅식 전
 
Lecture#5 c lang new
Lecture#5 c lang newLecture#5 c lang new
Lecture#5 c lang newZeeshan Ahmad
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !Rumman Ansari
 

Ähnlich wie C - ISRO (20)

5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Sachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin kumar ppt on programming in c
Sachin kumar ppt on programming in c
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
C tutorial
C tutorialC tutorial
C tutorial
 
1 c introduction
1 c introduction1 c introduction
1 c introduction
 
C tutorial
C tutorialC tutorial
C tutorial
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdf
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
C programming on Ubuntu
C programming on UbuntuC programming on Ubuntu
C programming on Ubuntu
 
basic program
basic programbasic program
basic program
 
Unit 5
Unit 5Unit 5
Unit 5
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005
 
Introduction to c language by nitesh
Introduction to c language by niteshIntroduction to c language by nitesh
Introduction to c language by nitesh
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
Lecture#5 c lang new
Lecture#5 c lang newLecture#5 c lang new
Lecture#5 c lang new
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !
 

Kürzlich hochgeladen

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 

Kürzlich hochgeladen (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 

C - ISRO

  • 1. C a series of presentations to help a bunch of brilliant space scientists understand a brilliant programming language
  • 2. Why? You wrote a really complex C program called super_complex_no_idea_what_i_justwrote.c
  • 3. Why? You use gcc to compile it . . . $ gcc super_complex_no_idea_what_i_justwrote.c
  • 7. Why? • Discovered a piece of C code in a book or the internet that solves your problem • Copied it into your program and somehow made it compile • No testing whatsoever • Program runs and gives you right output for your small set of conveniently selected input • Job done. Decided to comment your code later. Forgotten all about it. • Three months later someone comes and tells you to change your code for another input or someone comes and tells you that your code is not working. • Open your source code and stare at it ….. trying to make sense of what you did • Delete everything and go back to search a book or the internet to solve your problem
  • 8. hello world #include <stdio.h> int main(void) { text file named hello.c printf(“Hello Worldn”); return 0; } $ gcc hello.c compile $ a.out Hello World execute $
  • 9. Lets analyze it in detail . . . .
  • 10. a simple C program Instructs the preprocessor to #include <stdio.h> add the contents of the header file stdio.h into hello.c int main(void) next line { printf(“Hello Worldn”); return 0; }
  • 11. a simple C program Instructs the preprocessor to #include <stdio.h> add the contents of the header file stdio.h into hello.c int main(void) { printf(“Hello Worldn”); return 0; } Why does ‘stdio.h ‘have angle brackets <>? What is # include ? What is stdio.h? Where is it stored?
  • 12. a simple C program #include <stdio.h> Pre processor int main(void) directive { printf(“Hello Worldn”); return 0; } • Instructions meant for the pre-processor • Always being with a ‘#’ symbol • #include puts every line in the file stdio.h into hello.c • Other pre processor directive examples: #define, #ifdef #pragma, etc.
  • 13. a simple C program #include <stdio.h> Pre processor int main(void) directive { printf(“Hello Worldn”); return 0; } • < angle brackets > tells the #include directive to search for the file stdio.h in the standard C header file location. • The default standard C header files in a Unix machine is /usr/header, • We can use “ ” instead of < > to tell the include directive to first search for the file in the same directory as your C file, then the standard .
  • 14. a simple C program #include <stdio.h> Standard C headers int main(void) { printf(“Hello Worldn”); return 0; } • A file ending with ‘.h’ is known as a C header file. • A set of header files are available by default with the C programming language. These are known as standard C headers • The standard C headers contains declarations of system functions that allows you to invoke system calls and system libraries
  • 15. a simple C program #include <stdio.h> Standard C headers int main(void) { printf(“Hello Worldn”); return 0; } • stdio.h is one of the standard C headers that defines all standard input and output functions • In this program, we have an output function printf which is declared in stdio.h • stdio.h location is /usr/header/stdio.h
  • 16. a simple C program #include <stdio.h> main is the first function called int main(void) when you execute your { program. printf(“Hello Worldn”); next line return 0; }
  • 17. a simple C program #include <stdio.h> main is the first function called int main(void) when you execute your { program. printf(“Hello Worldn”); next line return 0; } What is int main(void)? Who calls main() function? Who decided the name ‘main()’? Why can’t I write my own function ‘start()’ ?
  • 18. a simple C program #include <stdio.h> int main(void) Main function { printf(“Hello Worldn”); return 0; } • Functions are a set of C instructions enclosed under a particular name. Eg: function name return type int add(int a, int b) parameters { int sum; instructions sum = a + b; return sum; } • Functions make our code readable
  • 19. a simple C program #include <stdio.h> int main(void) Main function { printf(“Hello Worldn”); return 0; } •main() is a special function that is first called when a C program is executed. Every C program must have only one main() function to execute. • int main( void ) tells us that the main() function takes no parameters as input and returns an integer as output •The main function is called by runtime environment of an operating system (Eg: in Unix, the program is executed by the shell interpreter. )
  • 20. a simple C program #include <stdio.h> int main(void) C Standard 99 { printf(“Hello Worldn”); return 0; } • C Standard 99 – is one of the many standards that put forward rules on how C programming language should be designed on different platforms (like Unix, Windows. Solaris, etc). This ensures a common functionality on all platforms • C Standard 99 – an ISO defined standard states that a C program should have the any one of the two main() function definitions int main(void) int main(int argc, char* argv[])
  • 21. a simple C program #include <stdio.h> int main(void) { printf function prints the printf(“Hello Worldn”); characters “Hello World ” return 0; to the standard output } stream. next line
  • 22. a simple C program #include <stdio.h> int main(void) { printf function prints the printf(“Hello Worldn”); characters “Hello World ” return 0; to the standard output. } What do you mean by ‘standard output stream’?
  • 23. a simple C program #include <stdio.h> Standard Streams int main(void) { printf(“Hello Worldn”); return 0; } • Standard output in C language is defined as the output to the terminal screen. ( in Unix, it is the shell window where the program was executed) • Along with standard output stream, C defines the standard input stream (keyboard) and standard error stream(screen again) • These are also defined in stdio.h as per C Standard 99 definitions
  • 24. a simple C program #include <stdio.h> int main(void) { printf(“Hello Worldn”); return 0; return the value 0. }
  • 25. a simple C program #include <stdio.h> int main(void) { printf(“Hello Worldn”); return 0; return the value 0. } Who did we just send ‘0’ to? Why are we returning ‘0’ ?
  • 26. a simple C program #include <stdio.h> int main(void) { printf(“Hello Worldn”); return 0; End of program } • The last line of main() function has a return 0; line where 0 is defined as a successful execution in C Standard 99. • It tells the runtime environment that the C program successfully executed all its lines of code. • The significance of this return value arises when the runtime environment executes multiple C programs. It helps it keep track of how many programs successfully executed.
  • 27. compile Run a program named gcc to compile the file hello.c $ gcc hello.c Notice that another file called a.out is created in the same folder
  • 28. compile Run a program named gcc to compile the file hello.c $ gcc hello.c Notice that another file called a.out is created in the same folder What exactly do you mean by ‘compile’? What is gcc ? Whats inside my executable ‘a.out’ ?
  • 29. compile $ gcc hello.c Compile • The process of converting a high level language (such as C language) instructions to a low level language (such as machine language 1’s and 0’s) instructions • Strictly speaking, the process of compiling does not yield an executable file… It is only one of the many steps involved in creating it.
  • 30. compile $ gcc hello.c What really Preprocessor (gcc) preprocessor to expand happens is… macros and includes header hello.i files Compiler (gcc) actual compilation of preprocessed source code hello.s to assembly language Assembler (as) convert assembly language into machine code and generate an object file hello.o Linker (ld) linking of object file with C run time libraries to create an executable a.out
  • 31. compile GNU Compiler $ gcc hello.c Collection (GCC) • This is a compiler system that is produced by the GNU (GNU Not Unix) Project. • Originally named GNU C Compiler, later changed after the inclusion of languages like C++, Ada, Fortran, Lisp, Java, Objective-C, Go, and many more. • Its open source!! • Website: http://gcc.gnu.org
  • 32. compile $ gcc hello.c a.out • The executable that is the available after the entire compilation and linking process • Its all 1’s and 0’s (binary) which only the machine can understand… you definitely cannot • All executables that are generated are always named a.out by default (can be overridden with the –o flag in gcc ) • ‘a.out’ name comes from a really old file format for executable files. Nowadays all executable files follow the ELF (Executable and Linkable Format)
  • 33. execute $ a.out Run a.out and see Hello World the line “Hello World” $ on the screen.
  • 34. execute $ a.out Run a.out and see Hello World the line “Hello World” $ on the screen. Wow!! That looked easy How did it all happen?
  • 35. execute $ a.out From Executable Hello World $ to a Process pid 22134 Memory Operating a.out Hard starting System Disk address CPU • a.out file is loaded by the operating system to memory (RAM) as an executing process. • Each process gets a unique id called process id (pid)
  • 36. execute $ a.out Memory Layout Hello World of your C program $ Command line arguments, Environment variables Stack Segment Now you know where the ‘segment’ in segmentation fault comes from  Heap Segment BSS Segment Initialized Data Segment Text Segment Memory Region
  • 37. … and that’s how it works
  • 38. what next? File I/O Data types Standard & structures C Library Pointers & Memory Allocation Debugging Macro and Version Pre Processor Management Multi file projects
  • 39. the creator of C… Dennis Ritchie 9th Sept 1941 – 12th Oct 2011
  • 40. Choose a job you love, and you will never have to work a day in your life - Confucious thank you