Unformatted text preview:

Hello World CS 2022 Introduction to C Instructor Hussam Abu Libdeh based on slides by Saikat Guha Fall 2011 Lecture 2 Hello World CS 2022 Fall 2011 Lecture 2 Administrivia Course twitter account http twitter com cs2022 I check here for announcements and real time updates Hello World CS 2022 Fall 2011 Lecture 2 Environment I I I I OS GNU Linux Editor vim Compiler gcc Debugger gdb Hello World CS 2022 Fall 2011 Lecture 2 Structure of a C Program Overall Program some pre processor directives global declarations global variables functions Hello World CS 2022 Fall 2011 Lecture 2 Structure of a C Program Functions function header local declarations statements Hello World CS 2022 Fall 2011 Lecture 2 hello c Hello World include stdio h int main printf Hello World n return 0 Hello World CS 2022 Fall 2011 Lecture 2 Compiling and Running I I gcc o hello hello c hello Hello World Hello World CS 2022 Fall 2011 Lecture 2 vars c Variables include stdio h int main int a b c a 10 b 20 c a b printf a d b d c d n a b c return 0 a 10 b 20 c 200 Hello World CS 2022 Fall 2011 Lecture 2 func c Functions include stdio h int add int a int b printf a d b d n a b return a b int main printf ret d n add 10 20 return 0 a 10 b 20 ret 30 Hello World CS 2022 Fall 2011 Lecture 2 cond c Conditionals include stdio h int main int i 10 if 10 i printf equal to ten n else printf not equal to ten n return 0 equal to ten Hello World CS 2022 Fall 2011 Lecture 2 loop c Loops include stdio h int main int i for i 0 i 10 i printf d i printf done n return 0 0 1 2 3 4 5 6 7 8 9 done Hello World CS 2022 Fall 2011 Lecture 2 rec c Recursion include stdio h void rec int a printf in d n a if a 0 rec a 1 printf out d n a int main rec 2 return 0 Hello World in 2 in 1 in 0 out 0 out 1 out 2 CS 2022 Fall 2011 Lecture 2 cmdarg c Command Line Args include stdio h int main int argc char argv int n m n atoi argv 1 m atoi argv 2 printf Argument 1 d nArgument 2 d n n m return 0 Argument 1 Argument 2 10 20 Hello World CS 2022 Fall 2011 Lecture 2 Bonus Problem Anagrams Given a 4 character string as a command line input print all anagrams that can be generated from it anagram abcd abcd abdc acbd acdb bacd Hint argv 1 2 is the 2nd character in the input string Hello World CS 2022 Fall 2011 Lecture 2


View Full Document

CORNELL CS 2022 - Lecture Notes

Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?