04-InputOutput.pptx - ICS 212 Program Structure William McDaniel Albritton M.S Memory Allocation Overview of C Hello World Program Program Execution in

04-InputOutput.pptx - ICS 212 Program Structure William...

This preview shows page 1 - 18 out of 49 pages.

ICS 212 Program Structure William McDaniel Albritton M.S.
Image of page 1
Memory Allocation Overview of C Hello World Program Program Execution in Unix C Programming Basics – variables, input, and output
Image of page 2
Image of page 3
Overview of C
Image of page 4
Overview of C Preceded by BCPL and B Developed by Dennis Ritchie Bell Labs in 1972 Portable (machine-independent) Used in UNIX, networks
Image of page 5
Image of page 6
Hello World Program
Image of page 7
Hello World Program Basic C program which outputs: Aloha! See example program file in Laulima: aloha.c /*Will ouput "Aloha!"*/ #include <stdio.h> int main(void){ printf("Aloha!\n"); return 0; }
Image of page 8
Comments Comments explain code to humans Start with a forward slash and asterisk (/*) End with an asterisk and forward slash (*/) Ignored by the C compiler /* One line of comments */ /* Two lines of comments */
Image of page 9
/* no comment */
Image of page 10
Preprocessor Lines beginning with pound sign (#) are processed by preprocessor before program is compiled This line of code tells the preprocessor to include the contents of the stdio.h file in the program #include <stdio.h>
Image of page 11
Header Files stdio.h - standard input/output header file Contains information and declarations about functions In this case, the printf() library function #include <stdio.h>
Image of page 12
Function Header The function header is the first line of a function definition, where the code of the function is written Has a return type: int Has a name: main (special function to start program) Has parameters: void (no parameters) int main(void)
Image of page 13
Function Body The function body contain the code of a function Starts/ends with left/right curly brackets: { } Has some code: printf("Aloha!\n"); Returns a value: return 0; (matches the return type) { printf("Aloha!\n"); return 0; }
Image of page 14
Image of page 15
Program Execution in UNIX
Image of page 16
6 Steps to Execute a C Program 1.Edit – write program code and store file on disk Edit program with Emacs (or Pico) Command is: emacs programName.c Creates a C program text file, which ends in ".c" Only the percent sign (%) is shown for the UNIX prompt % emacs program.c
Image of page 17
Image of page 18

You've reached the end of your free preview.

Want to read all 49 pages?

  • Spring '18
  •  Command,  End

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes