DOC PREVIEW
Rose-Hulman CSSE 432 - Study Notes

This preview shows page 1-2-3-4-5-6-7-48-49-50-51-52-53-54-97-98-99-100-101-102-103 out of 103 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 103 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Day 01 Introduction to CSaving Dyknow notesCreate a .cshrc fileWhy learn C (after Java)?Goals of this tutorialCreating an executableTypes of filesExternal library files libname.a or libname.soSlide 9Summarizing the ExampleCompiling and runningSlide 12Using external library filesPre-processor directivesExample of pre-processor directivesWhat is the output of the program?#defineSimple Data TypesSlide 19Slide 20Slide 21Slide 22Slide 23Slide 24String – an array of charactersSlide 26Strings – character arraySlide 28Slide 29Slide 30Other string functionsSlide 32Strings contd.Slide 34StructuresSlide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42User-defined header filesCommand line argumentsExample 7Slide 46File handlingSlide 48Slide 49Slide 50Slide 51Reading till end of fileSlide 53Functions – C methodsSlide 55Slide 56Complete the programSlide 58Slide 59Pointers made easy - 1Slide 61Pointer operationsSlide 63Pointers and arraysPointer arithmeticSlide 66Slide 67Slide 68Slide 69Man pages – Section 3Memory allocation for a process.See videoSlide 73Slide 74Dynamic arraySlide 76What is the output of the following program?What is the output of the following code segment?Array of PointersSlide 80For the following code segment, complete the diagrams provided to graphically represent the pointer creations and assignments. Again, line numbers are provided. You may assume that the malloc on line 2 allocates space starting at address 5000 and the malloc on line 3 allocates space starting at address 6000.Slide 82Common errors - Memory leakSlide 84Common erros - Dangling pointersIdentify the error in the following code segments and correct them?Slide 87Slide 88Slide 89Slide 90Slide 91Slide 92Slide 93Slide 94Input/Output statementsgdb - debuggerStorage classesStorage classes - contdProgram with multiple filesTo compileExternsSlide 102Before you go….1Day 01Introduction to CSaving Dyknow notesSave on the server.Can access from anywhere. Will have to install Dyknow on that machine.Must connect to the networkBring a thumb drive and save it on the drive at the end of class. Don’t have to connect to the network to access notes.Will have to install Dyknow on that machine.Download from http://www.dyknow.com/download/DyKnow Client 5.0 (x86) , Version 5.0.70The dyknow server is dyknow.cs.rose-hulman.eduCreate a .cshrc fileprompt> emacs .cshrcCreate aliases for common commandsAfter making changes, for the changes to take effect immediately:prompt> source .cshrc4Why learn C (after Java)?Both high-level and low-level languageBetter control of low-level mechanismsPerformance better than Java Java hides many details needed for writing OS code But,….Memory management responsibilityExplicit initialization and error detectionMore room for mistakes5Goals of this tutorialTo introduce some basic C concepts to youso that you can read further details on your ownTo warn you about common mistakes made by beginners6Creating an executableSource: http://www.eng.hawaii.edu/Tutor/Make/1-2.html7Types of filesC source files (.c)C header files (.h)Object files (.o)Executable files (typically no extension – by default : a.out)Library files (.a or .so)8External library fileslibname.a or libname.so Special functionality is provided in the form of external libraries of ready-made functions Ready-compiled code that the compiler merges, or links, with a C program during compilation For example, libraries of mathematical functions, string handling functions, and input/output functions Look for the library files under /usr/lib and header files under /usr/include9Example 1 – What is the output of this program?#include <stdio.h> //#include “myheader.h”intmain(){ printf(“Hello World. \n \t and you ! \n ”);/* print out a message */ return 0;}10Summarizing the Example#include <stdio.h> = include header file stdio.hNo semicolon at end Small letters only – C is case-sensitive int main(){ … } is the only code executed printf(“ /* message you want printed */ ”);  \n = newline \t = tab \ in front of other special characters within printf creates “escape sequences”.  printf(“Have you heard of \”The Rock\” ? \n”);11Compiling and running>gcc eg1.c (Creates a.out)>./a.out (Runs the executable)>gcc eg1.c –o eg1 (Creates eg1 not a.out)>./eg112To compile, use flag “l” and name i.e. –To compile, use flag “l” and name i.e. –lname.lname.Eg. gcc –o test test.c –lm Eg. gcc –o test test.c –lm where “m” in “lm” comes from libm.so where “m” in “lm” comes from libm.so i.e. the math library.i.e. the math library.13Using external library filesTo use the library files, you must:include the library header files You may also have to:link the library with a -l option to gcc14Pre-processor directivesA preprocessor is a program that examines C code before it is compiled and manipulates it in various ways. Two commonly used pre-processor directives#include – to include library files.#define - to define macros (names that are expanded by the preprocessor into pieces of text or C code)15Example of pre-processor directivesExample 2:#include <stdio.h> #define STRING1 "A macro definition\n" #define STRING2 "must be all on one line!\n" #define EXPRESSION1 1 + 2 + 3 + 4 #define EXPRESSION2 EXPRESSION1 + 10 #define ABS(x) ((x) < 0) ? -(x) : (x) #define MAX(a,b) (a < b) ? (b) : (a) #define BIGGEST(a,b,c) (MAX(a,b) < c) ? (c) : (MAX(a,b)) intmain (){ printf (STRING1); printf (STRING2); printf ("%d\n", EXPRESSION1); printf ("%d\n", EXPRESSION2); printf ("%d\n", ABS(-5)); printf ("Biggest of 1, 2, and 3 is %d\n", BIGGEST(1,2,3)); return 0; }What is the output of the program?17#defineThe expression is NOT evaluated when it replaces the macro in the pre-processing stage.Evaluation takes place only during the execution phase.18%i2short%l4long%lf8double%f4float%c1char%d %i4intShort-hand# of bytes (typical)Data-typeString - %s address - %p(HEX) or %u (unsigned int) Simple Data Types19#include <stdio.h>intmain(){int nstudents = 0; /* Initialization, required */ float age = 21.527;printf(“How many students does RHIT have ?”); scanf (“%d”, &nstudents); /* Read input */printf(“RHIT has %d students.\n”, nstudents); printf(“The average age of the students is


View Full Document

Rose-Hulman CSSE 432 - Study Notes

Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study 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 Study Notes 2 2 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?