SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Similar to 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 !
 

Recently uploaded

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

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