C Primer CAS CS210 Ying Ye Boston University. Outline Hello, world Basics in C Comparison of C and Java.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Basic Java Constructs and Data Types – Nuts and Bolts
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Hello World Program The source code #include int main() { printf("Hello World\n"); return(0); }
C Programming Day 1 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
Programming in C Pointers and Arrays, malloc( ). 7/28/092 Dynamic memory In Java, objects are created on the heap using reference variables and the new.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Pointers and Arrays C and Data Structures Baojian Hua
15213 C Primer 17 September Outline Overview comparison of C and Java Good evening Preprocessor Command line arguments Arrays and structures Pointers.
Arrays and Pointers in C Alan L. Cox
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
C Tutorial CSU480 Donghui Zhang Adapted from Wei Qian’s C tutorial slides.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Introduction to C Language
Pointers CSE 2451 Rong Shi.
Computer Science 210 Computer Organization Introduction to C.
CS 11 C track: lecture 1 Preliminaries Need a CS cluster account cgi-bin/sysadmin/account_request.cgi Need to know UNIX ITS.
13&14-2 Know the forms of loop statements in C (while,do/while,for). Understanding how data conversion occurs. Read/Write data in files using Unix redirection.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java ProgrammingtMyn1 Java Programming Timo Mynttinen Mikkeli University of Applied Sciences.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
#include int main(void) { printf("Hello, world!\n"); return 0; } entry point called on program start only one main( ) in any program # for preprocessor.
C Programming in Linux Jacob Chan. C/C++ and Java  Portable  Code written in one system and works in another  But in C, there are some libraries that.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Introduction to Programming
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Khalid Rasheed Shaikh Computer Programming Theory 1.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Pointers *, &, array similarities, functions, sizeof.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
1 CSC2100B Data Structure Tutorial 1 Online Judge and C.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
C Primer Session – 1/25/01 Outline Hello World Command Line Arguments Bit-wise Operators Dynamic Memory / Pointers Function Parameters Structures.
C is a high level language (HLL)
Announcements. Practice questions, with and without solutions will be uploaded by Friday 5 th November, make sure to check them before the weekend \\netstorage\Subjects\ITCA-b\Exam.
Tarik Booker CS 242. What we will cover…  Functions  Function Syntax  Local Variables  Global Variables  The Scope of Variables  Making Functions.
Object Oriented Programming Lecture 2: BallWorld.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
The Machine Model Memory
Computer Science 210 Computer Organization
C/C++ Tutorial.
C Primer.
CSE 220 – C Programming Pointers.
A bit of C programming Lecture 3 Uli Raich.
C Programming Tutorial – Part I
CSE 303 Concepts and Tools for Software Development
CS 61C: Great Ideas in Computer Architecture Introduction to C
C programming language
Computer Science 210 Computer Organization
An Introduction to Java – Part I, language basics
Govt. Polytechnic,Dhangar
#include <stdio.h> int main(void) { printf("Hello, world!\n");
CS 180 Assignment 6 Arrays.
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
C Programming Getting started Variables Basic C operators Conditionals
15213 C Primer 17 September 2002.
Introduction to java Part I By Shenglan Zhang.
Administrative things
C Tutorial Adapted from Wei Qian’s C tutorial slides.
Presentation transcript:

C Primer CAS CS210 Ying Ye Boston University

Outline Hello, world Basics in C Comparison of C and Java

Getting started Open PuTTY, connect to csa2 In your terminal, type in:  cd ~/Desktop  wget  vim hello.c

Hello, world #include tells compiler to add a library(stdio) into the program Why? ==> printf() int main(void):  program begins executing from main  equivalent to main(), but more standard:  int main(void);  int main(int argc, char *argv[]);

Hello, world printf("hello, world\n") prints out the character string passed to it return 0:  return value required by main() function  some compilers(like gcc) can add "return 0" automatically if your main function doesn't return a value(only in main function)

Hello, world Type in: gcc hello.c Try: ls Run:./a.out Want to specify the name? Try: gcc -o XXX(name you like) hello.c e.g.gcc -o abc hello.c Try ls again

Basics in C Basic types DatatypeSizeRange char to 127 short to int 4-2,147,483,648 to 2,147,483,647 long 4-2,147,483,648 to 2,147,483,647 float 43.4*10 +/-38 double 81.7*10 +/-308 (In 32-bit machine!) Arrays

Basics in C Operators  Arithmetic:  ++, --  +, -, *, /, %  Relational:  >, =, ==, !=  Logical:  &&, ||, !  Bitwise:  &, |, ^, >, ~  Assignment:  =, +=, -=, *=, /=, %=, &=, ^=, |=, >=

Basics in C Control flow  if...else  switch  while  do...while  for  continue/break

Basics in C Functions  Definition: return-type function-name(parameter declarations) { declarations statements }  Note: If you want to use a function before you define it in the source code, you should declare the function before using it. Example: C textbook page 24

Basics in C  Call by value: void swap(int a, int b) {int c = a; a = b; b = c;} int main(void) {int x = 1, y = 2; swap(x, y); return 0; }

C and Java { for(int i = 0; i < 10; i++) printf("hello, world\n"); return 0; } Add an option in gcc: gcc -o XXX -std=c99 hello.c {int i; for(i = 0; i < 10; i++) printf("hello, world\n"); return 0; }

C and Java Uninitialized variables:  In Java: Instance variables initialized to 0, null, or false  In C: Initialized to random values No exceptions in C: return specific value to indicate error No string data type in C: use arrays to store character strings e.g. char name[5] = {'J', 'o', 'h', 'n', '\0'};

Macros  Definition: A macro is a fragment of code which has been given a name. Whenever the name is used, it is represented by the contents of the macro. #define macro_name contents_of_macro  Usages:  Define a number as a macro: #define TOTAL 100 int a = TOTAL;  Define a character string: #define NAME "John" printf(NAME);  Define a function: #define ADD(a, b) a += b int x = 1, y = 2;ADD(x, y);