Introduction to C Programming- Session2

Introduction to C Programming- Session2 - Introduction to C...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to C Programming CS 049 Laboratory Nima Bari
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
vi Pico Emacs Xcode MS visual studio gcc –c test.c gcc –o results test.c ./results
Image of page 2
A Simple C Program /* Filename: test.c Programmer: Nima Bari Date written: September 10 th , 2012 Description: This program prints the greeting “Hello, World!” */ #include <stdio.h> int main ( void ) { printf ( “Hello, World!\n” ) ; return 0 ; }
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
/* program header comment */ preprocessor directives (if any) int main ( void ) { statement(s) return 0 ; }
Image of page 4
Comments Text surrounded by /* and */ is ignored by computer Used to describe program #include <stdio.h> Preprocessor directive Tells computer to load contents of a certain file <stdio.h> allows standard input/output operations int main() C programs contain one or more functions, exactly one of which must be main Parenthesis used to indicate a function int means that main "returns" an integer value Braces ( { and } ) indicate a block The bodies of all functions must be contained in braces
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
printf( “Hello, World!\n" ); Instructs computer to perform an action Specifically, prints the string of characters within quotes ( ) Entire line called a statement All statements must end with a semicolon ( ; ) Escape character ( \ ) Indicates that printf should do something out of the ordinary \n is the newline character return 0; A way to exit a function return 0
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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