Main differences with Java
|
|
- Moses Harrell
- 6 years ago
- Views:
Transcription
1 Signals, Instruments, and Systems W2 C Programming (continued)
2 C
3 Main differences with Java C is NOT object oriented. (C++ is OO) C code is directly translated into binary that can be directly executed by the machine. Java is an interpreted language (Bytecode) With C, the programmer can directly access machine resources (memory, processes). In Java, code is executed within a Virtual Machine (safe)
4 Main differences with Matlab Matlab is an interpreted language Interpreted: The code is transformed into machine executable code at run-time Matlab is optimized for matrix operations Syntax differences (loops, functions, etc ) No variable declarations
5 How to use it? file.c? file source file executable (binary)
6 How to use it? gcc file.c o file file.c object file file.o file source file libc executable standard C library gcc is a program, and stands for Gnu C Compiler It contains all standard libraries
7 Libraries Libraries provide special functionality in the form of collections of ready-made functions: Library: Example: stdio.h printf(const char* format, ) math.h sqrt(double x) time.h gettimeofday() stdlib.h rand() Usage: #include <stdlib.h> #include my_library.h :a collection of function declarations
8 Main source file Compilation 3 main.c main.o gcc help.o file.o main.c o program -lm Complementary file 1 help.c epc help.o epo program gcc c help.c o help.o Complementary file 2 file.c file.o libc libm gcc c file.c o file.o standard C library math library
9 Makefile: Example (see previous slide) CC = gcc LDFLAGS = -lm all: main - compiler -additional library - targets main: main.o help.o file.o - label clean: rm rf *.o main -[TAB]!! Note: Run make clean all for a totally new compilation
10 Example: Hello World In Java class myclass { public static void main(string args[]) { System.out.println("Hello World!"); #include <stdio.h> In C int main(int argc, char *args[]) { printf( Hello World! ); return 0;
11 Example: Hello World int main(int argc, char *args[]) That is the entry function of any C code. This function is called first when the program gets executed. #include <stdio.h> printf( Hello World! ); This function is in the libc. return 0; It is declared in the stdio.h file. return 0; main always returns an int (integer value). The convention is to return 0 when everything went ok. #include <stdio.h> Includes the declaration of printf in our C code. int main(int argc, char *args[]) { printf( Hello World! );
12 Variables Just like Java there are several types of variables: Integers: char, short, int, long Floating point: float, double Characters: char There is no Boolean type. Variables can be either signed or unsigned: e.g. unsigned int, signed char
13 Variables Variables need to be declared before they are used. In correct ANSI C89, variables need to be declared at the beginning of a block (after { ). int main() { int a = 5; double b = 4.3; return (int)((double)a * b); Remark: A variable type can be modified with a cast.
14 Variables - Cast The cast operator is an operator which forces a particular type mould or type cast onto a value: char ch = a ; int i; i = (int)ch; int i = 1; int j = 3; double k; k = i/j; int i = 1; int j = 3; double k; k = (double)i/ (double)j; i = 97 k = 0 k = careful!
15 Variables - enum Enumeration of tags. The tags are numbered (0,1,..) (,,) by default. Def.: enum identifier { enumerator-list Ex.: enum BOOLEAN { false, // =0 true ; // =1 enum BOOLEAN is_empty = false;
16 Variables - typedef Typedef allows you to define your own types. Def.: typedef type typedef-name Ex.: typedef int BOOLEAN; BOOLEAN is_empty = 0;
17 Operators - Logical Operator e1 < e2 e1 <= e2 e1 > e2 e1 >= e2 e1 == e2 e1!= e2 e1 && e2 e1 e2 Meaning less than less than or equal greater than greater than or equal equal to not equal to logical AND logical OR
18 Operators - Shortcuts Operator e1 *= e2 e1 /= e2 e1 += e2 e1 -= e2 e1 %= e2 Meaning multiplication division addition subtraction modulo Note: a+= 1 is the same as a++
19 Operators - Bitwise Operator e1 << e2 e1 >> e2 e1 e2 e1 & e2 e1 ^ e2 Meaning left shift right shift bitwise OR bitwise AND exclusive OR Question: Hint: 20 << 2 =? << 2 = >> 2 =? Note: Bitwise calculus is used in advanced code (compression, encryption, or optimizations) and also in embedded systems
20 Controlling the execution flow Algorithms are all about controlling the execution flow. Algorithms are all about deciding how to proceed depending on some conditional statements. What are the tools we use to do this?
21 if Def.: Ex.: if (condition) { code; else if (another condition) { another code; else { yet another code; if (a >= b && a!= c) { a = b; else if (a == 3 b == 3) { a = c; else { b = 2*a;
22 while Def.: while (condition) { code; do { code; while (condition); At any time, you can quit the loop with the keyword break. You can also skip the rest of the code in the loop with continue.
23 for Df Def.: for (initialization; iti condition; increment) { code; Ex.: for (i = 0; i < i_max; i++) { a = a + i * a; printf( a is equal to: %d \n, a); continue and break can also be used.
24 switch Def.: switch (expression) { case constant1: break; statements; case constant2: break; statements; Ex.: switch (state) { case SLEEP: sleep_time++; break; case AWAKE: awake_time++; break; default: other_state_time++; default: statements;
25 stdin - stdout Standard input and standard output are file streams printf( Hello ) is equivalent to fprintf(stdout, Hello ) scanf( %d, &i) is equivalent to fscanf(stdin, %d, &i) stderr is useful to display errors, because it is not affected by redirection (>):./my_program > out.txt -- the errors will still be displayed! KEYBOARD stdin PROGRAM DISPLAY stdout / stderr
26 Printing Format Most commonly used: %d integer %u unsigned integer %f double %s string %c char Object Control spec. Actual output 42 %6d 42 z %3c z %10f % printf %s printf
27 Functions Repetition: If part of the code needs to be repeated several times (more than one), create a function! Structure: If part of the code seems like a subtask of your complete code, create a function!
28 Why? int main() { matrix A = creatematrix(3,3); A[0][2] = 2.0; printmatrix(a); destroymatrix(a); return 0; = int main() { int i, j; double **A = malloc(3*sizeof(double *)); for (i = 0; i < 3; i++) { A[i] = malloc(3*sizeof(double *)); A[0][2] = 2.0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { printf( %.2f, A[i][j]); printf( \n ); for (i = 0; i < 3; i++) { free(a[i]); free(a); return 0;
29 Functions: how? Functions output a type Functions can also take inputs. type name(type1 arg1, type2 arg2, ); Examples: int main(int argc, char *args[]); double cos(double angle); void my_function();
30 Functions Before using a function, it has to be declared. Unlike Java, C can only back reference: #include <stdio.h> int main(int argc, char *args[]) { print _ hello_ world(); return 0; void print_hello_world() _ { printf( Hello World! ); #include <stdio.h> void print_hello_world() { printf( Hello World! ); int main(int argc, char *args[]) { print_hello_world(); return 0;
31 Example: π #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> double compute_pi(int p); int main(int argc, char *args[]) { int precision; double pi; if (argc < 2) { fprintf(stderr, "Usage: %s [precision]\n", args[0]); return -1; 1 include the needed functionalities 2 declare the functions 3 main 4 declare needed variables at the beginning g of the block precision = atoi(args[1]); pi = compute_pi(precision); printf("the final value is %.6f\n 6f\n, pi); printf( The real value is %.6f)\n", M_PI); return 0; 5 call your function 6 return
32 Example: π double compute_pi(int p) { int i; int inside = 0; double ratio; 6 write the declared function 7 declare variables srand(time(null)); for (i = 0; i < p; i++) { double x = 2.0*(double) (rand() () - RAND_ MAX/2)/(double)RAND/ ) _ MAX; ; double y = 2.0*(double) (rand() - RAND_MAX/2)/(double)RAND_MAX; if (x*x + y*y < 1) inside++; ratio = (double)inside/(double)p; return ratio*4.0; 8 return value
33 Arrays To declare an array: Def.: type name[size]; e.g. double vector[3]; or double matrix[4][6]; To access: name[index] e.g. vector[1] = 4.5; or double a = matrix[0][2]; Remark: indices start at 0 (not 1 like Matlab).
34 Example: Arrays int main() { int i, j; double A[3][3]; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { A[i][j] = 0; A[0][2] = 2.0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { printf( %.2f, A[i][j]); printf( \n ); return 0;
35 Structures Structures can potentially replace objects (from Java). Just like any other variable a atructure needs to be declared before being used: struct pose { double x; double y; double angle; ; struct pose p; The new structure represents a new variable type.
36 Structures To declare a variable from a structure: struct struct_ name name; ; e.g. struct pose vehicle_position; To access part of a structure: name.member e.g. vehicle_position.x iti = 3.0; or double a = vehicle_position.angle;
37 struct vec2 { double x; double y; ; Example: Structures double scalar_prod(struct t vec2 v1, struct t vec2 v2) { return v1.x*v2.x + v1.y*v2.y; int main() { struct vec2 v1, v2; v1.x = 1.0; v1.y = 1.0; v2.x = 0.0; v2.y = 2.0; printf( Scalar product equal to %.2f\n, scalar_prod(v1, v2)); return 0;
38 Example: Matrices (1) Example of all elements you have seen until now we will create: a minimalist matrix-library a main function that uses it a Makefile that compiles it
39 Example: Matrices (2) matrix.h #ifndef f _MATRIX_H #define _MATRIX_H #define MAX_ROWS 100 #define MAX_COLS 100 typedef struct { double values[max_rows][max_cols]; unsigned int nrows; unsigned int ncols; matrix_t; matrix_t t transpose(matrix_t t A); matrix_t add(matrix_t A, matrix_t B); void print(matrix_t A); #endif
40 Example: Matrices (2) matrix.c (1) #include "matrix matrix.h h" #include <stdio.h> matrix_t transpose(matrix_t A) { matrix_t t B; unsigned int i, j; B.nrows = A.ncols; B.ncols = A.nrows; for (i = 0; i < A.nrows; i++) { for (j = 0; j < A.ncols; j++) { // Simply assign columns to rows B.values[j][i] = A.values[i][j]; return B;
41 Example: Matrices (3) matrix.c (2) matrix_t t add(matrix_t t A, matrix_t t B){ matrix_t C; unsigned int i, j; C.nrows = 0; C.ncols = 0; // Sanity check if (A.nrows!= B.nrows A.ncols!= B.ncols) return C; C.nrows = A.nrows; C.ncols = A.ncols; for (i = 0; i < A.nrows; i++) { for (j = 0; j < A.ncols; j++) { C.values[i][j] = A.values[i][j] + B.values[i][j]; return C;
42 Example: Matrices (4) matrix.c (3) void print(matrix_t A) { unsigned int i, j; for (i = 0; i < A.nrows; i++) { printf(" "); for (j = 0; j < A.ncols; j++) { printf("%8.2f ", A.values[i][j]); printf(" \n"); return;
43 Example: Matrices (5) main.c #include <stdio.h> #include "matrix.h" int main(int argc, char *args[]) { matrix_t A, B, C; A.nrows = 2; A.ncols = 2; B.nrows = 2; B.ncols = 2; A.values[0][0] = 1.0; A.values[0][1] = 2.0; A.values[1][0] = 3.0; A.values[1][1] = 4.0; B.values[0][0] = 1.0; B.values[0][1] = 2.0; B.values[1][0] = 3.0; B.values[1][1] = 4.0; printf("a = \n"); print(a); printf("b = \n"); print(b); C = add(a,b); printf("a + B = \n"); print(c); C = add(transpose(a), B); printf("a' + B = \n"); print(c); return 0;
44 Example: Matrices (6) Makefile CC = gcc all: main main: matrix.o main.o clean: rm -rf *.o main
45 Example: Matrices (7) stdout A = B = A + B = A' + B =
46 Remember man? You can use man to show information about functions in the standard libraries of C: e.g. man printf or man atan2 To type in the terminal!
47 Conclusion
48 Summary You have seen almost all basics of C Next week,,you will see the pointers. Pointers are a way to access specific places in the computer memory and are a main element of C programming. C resembles Java in syntax, but not in execution. Matlab is a very useful mathematical tool, but is weak for real-time processing
Signals, Instruments, and Systems W2. C Programming (continued)
Signals, Instruments, and Systems W2 C Programming (continued) 1 Resources 2 Remember man? You can use man to show information about functions in the standard libraries of C: e.g. man printf or man atan2
More informationSignals, Instruments, and Systems
Signals, Instruments, and Systems School of Architecture, Civil and Environmental Engineering EPFL, SS 2016-2017 http://disal.epfl.ch/teaching/signals_instruments_systems/ 1 Signals, Instruments, and Systems
More informationSignals, Instruments, and Systems
Signals, Instruments, and Systems School of Architecture, Civil and Environmental Engineering EPFL, SS 2013-2014 http://disal.epfl.ch/teaching/signals_instruments_systems/ 1 Signals, Instruments, and Systems
More informationCS 61C: Great Ideas in Computer Architecture Introduction to C
CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction
More informationSignals, Instruments, and Systems W3. C Programming & Memory Management in C
Signals, Instruments, and Systems W3 C Programming & Memory Management in C 1 Remarks 2 Indentation, indentation, indentation, Indentation and spacing helps you and others (= TAs) read your code. It has
More informationC/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)
C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 By the end of this lecture, you will be able to identify the
More informationC/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for
C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 1 By the end of this lecture, you will be able to identify
More informationKurt Schmidt. October 30, 2018
to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed
More informationLecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions
Lecture 02 Summary C/Java Syntax Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 1 2 By the end of this lecture, you will be able to identify the
More informationBasic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types
More informationC introduction: part 1
What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation
More informationPrinceton University COS 333: Advanced Programming Techniques A Subset of C90
Princeton University COS 333: Advanced Programming Techniques A Subset of C90 Program Structure /* Print "hello, world" to stdout. Return 0. */ { printf("hello, world\n"); -----------------------------------------------------------------------------------
More informationIntroduction to C An overview of the programming language C, syntax, data types and input/output
Introduction to C An overview of the programming language C, syntax, data types and input/output Teil I. a first C program TU Bergakademie Freiberg INMO M. Brändel 2018-10-23 1 PROGRAMMING LANGUAGE C is
More informationComputers Programming Course 6. Iulian Năstac
Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap
More informationMatlab? Chapter 3-4 Matlab and IPT Basics. Working Environment. Matlab Demo. Array. Data Type. MATLAB Desktop:
Matlab? Lecture Slides ME 4060 Machine Vision and Vision-based Control Chapter 3-4 Matlab and IPT Basics By Dr. Debao Zhou 1 MATric LABoratory data analysis, prototype and visualization Matrix operation
More informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More informationEL2310 Scientific Programming
Lecture 7: Introduction to C (pronobis@kth.se) Overview Overview Lecture 7: Introduction to C Wrap Up Basic Datatypes and printf Branching and Loops in C Constant values Wrap Up Lecture 7: Introduction
More informationCS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco
CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level
More informationC Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017
C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More informationC OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure
C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces
More informationFundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University
Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler
More informationTopic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History
Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program
More informationA Short Course for REU Students Summer Instructor: Ben Ransford
C A Short Course for REU Students Summer 2008 Instructor: Ben Ransford http://www.cs.umass.edu/~ransford/ ransford@cs.umass.edu 1 Outline Today: basic syntax, compilation Next time: pointers, I/O, libraries
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More information2. Numbers In, Numbers Out
COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break
More informationAn Ungentle Introduction to C
Warum C? - Sicherheit auf allen Systemschichten Applikationen Hilfssysteme BS-Werkzeuge BS-Kern HW Evtl. Hochsprachen Skripte C Assembler - je tiefer die kompromittierte Schicht, umso größer der Schaden
More informationProgramming refresher and intro to C programming
Applied mechatronics Programming refresher and intro to C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2018 Outline 1 C programming intro 2
More informationApplied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011
Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and
More informationCSSE 332 Standard Library, Storage classes, and Make
CSSE 332 Standard Library, Storage classes, and Make 1 Provides a simple and efficient buffered I/O interface from man stdio Prototypes standard I/O functions (Mostly) system-independent (e.g.
More informationObject-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018
Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative
More information6.096 Introduction to C++ January (IAP) 2009
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture
More informationIntroduction to C Language
Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,
More informationadvanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef
today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation
More informationComputers Programming Course 7. Iulian Năstac
Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument
More informationLaboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information
Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify
More informationOBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING LAB 1 REVIEW THE STRUCTURE OF A C/C++ PROGRAM. TESTING PROGRAMMING SKILLS. COMPARISON BETWEEN PROCEDURAL PROGRAMMING AND OBJECT ORIENTED PROGRAMMING Course basics The Object
More information#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;
1. Short answer questions: (a) Compare the typical contents of a module s header file to the contents of a module s implementation file. Which of these files defines the interface between a module and
More informationTopic 6: A Quick Intro To C
Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions
More informationComputers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
More informationLecture 03 Bits, Bytes and Data Types
Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics
More informationLecture 3. More About C
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants
More informationPRINCIPLES OF OPERATING SYSTEMS
PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)
More informationRecap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam
Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine
More informationThe C standard library
C introduction The C standard library The C standard library 1 / 12 Contents Do not reinvent the wheel Useful headers Man page The C standard library 2 / 12 The Hitchhiker s Guide to the standard library
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More informationEL2310 Scientific Programming
Lecture 12: Memory, Files and Bitoperations (pronobis@kth.se) Overview Overview Lecture 12: Memory, Files and Bit operations Wrap Up Main function; reading and writing Bitwise Operations Wrap Up Lecture
More informationC-Programming. Claude Fuhrer 5 août 2017
C-Programming Claude Fuhrer (claude.fuhrer@bfh.ch) 5 août 2017 1 Pseudocode The most important step in writing a program, is to understand the problem which should be solved and then establish a strategy
More informationGetting started with Java
Getting started with Java by Vlad Costel Ungureanu for Learn Stuff Programming Languages A programming language is a formal constructed language designed to communicate instructions to a machine, particularly
More informationRicardo Rocha. Department of Computer Science Faculty of Sciences University of Porto
Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationIntroduction to Supercomputing
Introduction to Supercomputing TMA4280 Introduction to UNIX environment and tools 0.1 Getting started with the environment and the bash shell interpreter Desktop computers are usually operated from a graphical
More informationSWEN-250 Personal SE. Introduction to C
SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the
More information2. Numbers In, Numbers Out
REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write
More informationTwo s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011
Two s Complement Review CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part I) Instructor: Michael Greenbaum http://inst.eecs.berkeley.edu/~cs61c/su11 Suppose we had
More informationFriday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week
Friday, September 16, 2016 Lab Notes Topics for today Redirection of input and output Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week 1. Redirection
More informationCharacter Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
More informationHigh-performance computing and programming I. Introduction to C programming in *NIX
High-performance computing and programming I Introduction to C programming in *NIX Writing C programs in Unix/Linux Writing code Building code compile with gcc (or cc) link with gcc (or ld) make Environment
More informationDeep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems
Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse
More informationTHE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming
THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY ISA 563: Fundamentals of Systems Programming Announcements Homework 2 posted Homework 1 due in two weeks Typo on HW1 (definition of Fib. Sequence incorrect)
More informationData Type Fall 2014 Jinkyu Jeong
Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationcs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).
cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion
More informationCS Basics 15) Compiling a C prog.
CS Basics 15) Compiling a C prog. Emmanuel Benoist Fall Term 2016-17 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1 Compiling a C program Example of a small
More informationBerner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2
Compiling a C program CS Basics 15) Compiling a C prog. Emmanuel Benoist Fall Term 2016-17 Example of a small program Makefile Define Variables Compilation options Conclusion Berner Fachhochschule Haute
More informationFriday, February 10, Lab Notes
Friday, February 10, 2017 Lab Notes Topics for today Structures in C Redirection of input and output in a Unix-like environment Command line arguments More pre-processor options Programs: Finish Program
More informationCreating a C++ Program
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an
More informationJTSK Programming in C II C-Lab II. Lecture 3 & 4
JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Pointers Pointers denote addresses in memory In C types, the * represents the use
More informationWriting an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and
Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()
More informationC Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering.
C Tutorial: Part 1 Dr. Charalampos C. Tsimenidis Newcastle University School of Electrical and Electronic Engineering September 2013 Why C? Small (32 keywords) Stable Existing code base Fast Low-level
More informationANSI C Programming Simple Programs
ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double
More informationTutorial 1: Introduction to C Computer Architecture and Systems Programming ( )
Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough
More informationCOMP322 - Introduction to C++ Lecture 02 - Basics of C++
COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.
More informationLab 2: More Advanced C
Lab 2: More Advanced C CIS*2520 Data Structures (S08) TA: El Sayed Mahmoud This presentation is created by many TAs of previous years and updated to satisfy the requirements of the course in this semester.
More informationArrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]
(November 10, 2009 2.1 ) Arrays An array is a collection of several elements of the same type. An array variable is declared as type array name[size] I The elements are numbered as 0, 1, 2... size-1 I
More informationCompiling and Running a C Program in Unix
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 95 ] Compiling and Running a C Program in Unix Simple scenario in which your program is in a single file: Suppose you want to name
More informationLanguage Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science
Language Design COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Language Design Issues Syntax: how programs look Names and reserved words Instruction
More informationLecture 02 C FUNDAMENTALS
Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void
More informationCopyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented
More informationGoals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"
Goals of this Lecture The Design of C: A Rational Reconstruction Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C Why? Learning
More informationLesson 5: Functions and Libraries. EE3490E: Programming S1 2018/2019 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology
Lesson 5: Functions and Libraries 1 Functions 2 Overview Function is a block of statements which performs a specific task, and can be called by others Each function has a name (not identical to any other),
More informationHigh-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet
High-performance computing and programming Intro to C on Unix/Linux IT Uppsala universitet What is C? An old imperative language that remains rooted close to the hardware C is relatively small and easy
More informationThe Design of C: A Rational Reconstruction: Part 2
The Design of C: A Rational Reconstruction: Part 2 1 Continued from previous lecture 2 Agenda Data Types Operators Statements I/O Facilities 3 Operators Issue: What kinds of operators should C have? Thought
More informationTools : The Java Compiler. The Java Interpreter. The Java Debugger
Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,
More informationLecture 8: Structs & File I/O
....... \ \ \ / / / / \ \ \ \ / \ / \ \ \ V /,----' / ^ \ \.--..--. / ^ \ `--- ----` / ^ \. ` > < / /_\ \. ` / /_\ \ / /_\ \ `--' \ /. \ `----. / \ \ '--' '--' / \ / \ \ / \ / / \ \ (_ ) \ (_ ) / / \ \
More informationWork relative to other classes
Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language
More informationch = argv[i][++j]; /* why does ++j but j++ does not? */
CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and
More informationGuide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:
Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required
More informationC Language Summary (Continued)
Chris J Michael cmicha1@lsu.edu 11 September 2008 C Language Summary (Continued) Heavily Influenced by the GNU C Reference Manual: http://www.gnu.org/software/gnu-c-manual/ Q/A -Somebody brought up a nice
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationProgramming. C++ Basics
Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++
More informationC PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5
C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 1. Pointers As Kernighan and Ritchie state, a pointer is a variable that contains the address of a variable. They have been
More informationHigh Performance Computing MPI and C-Language Seminars 2009
High Performance Computing - Seminar Plan Welcome to the High Performance Computing seminars for 2009. Aims: Introduce the C Programming Language. Basic coverage of C and programming techniques needed
More informationCourse Outline Introduction to C-Programming
ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,
More informationContinued from previous lecture
The Design of C: A Rational Reconstruction: Part 2 Jennifer Rexford Continued from previous lecture 2 Agenda Data Types Statements What kinds of operators should C have? Should handle typical operations
More informationHigh Performance Computing
High Performance Computing MPI and C-Language Seminars 2009 Photo Credit: NOAA (IBM Hardware) High Performance Computing - Seminar Plan Seminar Plan for Weeks 1-5 Week 1 - Introduction, Data Types, Control
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch
More information