Basic Common Unix commands: Change to directory d

Size: px
Start display at page:

Download "Basic Common Unix commands: Change to directory d"

Transcription

1 Basic Common Unix commands: cd d Change to directory d mkdir d rmdir d mv f1 [f2...] d mv d1 d2 ls [d] [f...] ls -1 [f...] vi [f] emacs [f] more f cp f1 f2 mv f1 f2 rm f gcc [-o f1] f2 gnuplot Create new directory d Remove directory d Move file f to directory d Rename directory d1 as d2 List files in directory List files in detail Vi fullscreen editor Emacs fullscreen editor List file contents by screen Copy file f1 into f2 Rename file f1 as f2 Delete (remove) file f GNU C compiler Run plotting program gnuplot C Language A First For any C programming, it involves the following four steps. Saluting the World. Step 1. Create the source file Use your favorite editor (if you are working in cygwin environment, you even can use notepad as the editor) to type the following lines (you may skip the comments): #include <stdio.h> // main function. All the c programs must have a main function. // begin of main function printf("hello world!\n"); //call printf which is an outpuf function from stdio.h library. //the \n is the new line character // end of main function. Save the file with a name of your choice, for example, hellowrold.c. Make sure that the file has an extension c. Unix and C Page 1

2 Step 2. Compile the source file Under unix environment, go to the directory where the hellowrld.c is saved, type: gcc helloworld.c o hellworld If there is no error message reported by the compiler, then the source code has passed the compiling and an executable file helloworld should be created under the same directory. Step 3. Debug the source file If you get error or complain in the compiling process, you need go back to step 1 and fix it; then compile the source file until no error is reported. Step 4. Run the executable file: At the working directory, type the name of executable file, in this case, helloworld, you will see a line of Hello World! printed out on your screen. Example 2 Add two numbers A C program can have multiple functions. The following example defines a function called add_two_numbers which is then twice called by the main function. #include <stdio.h> add_two_numbers(2000, 8); // function call add_two_numbers(2000,- 8); // function call add_two_numbers(int a, int b) // a function which prints the sum of two integers a and b int c; // define c as integer type c = a + b; printf( The sum of %d and %d is %d.\n, a, b, c); Compile the program and run it, you should see the following line on your screen: The sum of 2000 and -8 is The sum of 2000 and 8 is A Quick Tutorial on C Variables in C A variable must be declared before it can be sued. A declaration begins with the type, followed by the name of one or more variables. int high, low, results[20]; Declarations can also be spread out. int high; int low; int results[20]; The most common types are: int an integer float a floating point number (real number) double a double precision floating point number char a single byte of memory to hold a character Unix and C Page 2

3 Local variables and global variables Local variables are declared within the body of a function and can only be used within that function; Global variables are located outside any of the program s function; usually this is done at the beginning of the program. Constants Number constants, examples: 1, 0.5, 12.e9. Character constansts, examples: a, b, \n Arrays An array is a collection of variables of the same type. Array elements are identified by an integer index with zero for the first element. int results[20]; float data[200]; For higher dimensions; int results[20][10]; As an example, here is a simple function to add up all of the integers in a single dimensioned array. int add_array(int array[], int size) // the size of array is determined when this function is called int i; int total = 0; for(i = 0; i < size; i++) total += array[i]; return(total); Expressions and operators Arithmetic operators: +, -, *, /, % (remainder from integer division) Assignment statement y=(m*x)+c ; which will save the value of the expression in variable y. Shorthand for some expressions i++; equivalent to: i=i+1; i--; equivalent to: i=i-1; i += 10; i=i+10; i -=10; i=i-10; i *=10; i=i*10; i /=10; i=i/10; Type conversion You can mix the types of values in your arithmetic expressions. But sometime you need apply type conversion to avoid trouble. int a=12, b=24; float x; x=(float)a/(float)b; Unix and C Page 3

4 The cast is made by putting the bracketed name of the required type just before the value. Comparison C notation Meaning == Equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to!= Not equal to Note that == is used in comparisons and = is used in assignments. float max(float a, float b) float max; if (a>=b) max=a; else max=b; return max; Logical oconnectors: && and or! not Check if a number is even or odd. If a number is even, the function returns 1; otherwise, it returns 0. int even_odd(int a) If(a!=0 && (a%2==0)) return 1; else return 0; Control statements If else statement Example. if(result >=60) printf( Pass\n ); else printf( Fail\n ); The loop statement Unix and C Page 4

5 While, do while and for Add the first 100 positive integers: int sum_of_1_100() int i,sum; i=1; sum=0; while (i<=100) sum=sum+i; i=i+1; return sum; Or int sum_of_1_100() int i,sum; sum=0; for(i=1;i<=100;i++) sum=sum+i; return sum; or int sum_of_1_100() int i,sum; i=1; sum=0; do sum=sum+i; i=i+1; while(i<=100); return sum; Functions in c A c program can have multiple functions besides the main function. Let s use the following example to explain all the elements of a function. a function which converts the temperture from of to oc: double convert(double Tf) double Tc; Tc=(Tf-32)*5./9.; Return Tc; Let us examine the details of this function: double convert(double Tf) Unix and C Page 5

6 This line is the function definition. It tells us the type of the return value is double; the name of the function is convert; the argument used by the function is Tf. Another example which return noting (void): void error_message(int line) printf( Error in line %d\n, line); Return value in function using a pointer There is another way to return a value through function, which is using a pointer. A pointer points to the address of a piece of memory. int *res; this tells us that res is a pointer to a address which stores an integer, and the value stored in the memory is *res. void convert (double Tf, double *Tc) *Tc=(Tf-32)*5./9.; To call the above function, double a=73, b; convert(a,&b); // we created a pointer to double by using &b which represents the address of b. Test the following program to get a better understanding. #include <stdio.h> void convert(double a, double *b); double a=73.,b; convert(a,&b); printf("tem is %lf \n",b); printf("address of b is %d\n",&b); void convert(double a, double *b) *b=(a-32.)*5./9.; printf("inside address is %d\n",b); Input and output: scanf and printf For formatted input or output, Control string entry What gets printed %d A decimal integer %f A floating value Unix and C Page 6

7 %lf A double precision floating number %e Exponential representation %c A character %s A character string float x; scanf( %f\n,&x); // scanf needs to know the address of the items to be read! printf( the input data is %f\n,x); You can also insert numbers into the control strong to control field widths for values to be printed. printf( %10.5\n,x); This will display x in a number of a filed 10 spaces wide with room to show 5 decimal places. File Handling C communicates with files using a file pointer, FILE *. Example, a file pointer fp is declared below: FILE *fp; Open a file: fp=fopen( output_file, w ); It takes two string araguments, the first is the name of the file to be opened, the second is an access character which can be one of r, w or a (for reading, writing or appending, respectively). Close a file: fclose(fp); this releases the file pointer fp. C language keywords: Auto break case char continue default do double else enum extern float for goto if int long register return short sizeof static struct switch typedef union unsigned void while. These keywords have already defined in the C language and cannot be re-defined. Guidelines for Writing a Code 1. Write all code so that anybody unfamiliar with the work can understand it as quickly as possible. a. Start all subprograms with a header block of comments, clearly defining the purpose of the subprogram, defining and delineating all input arguments and output arguments, and giving your name and date the subprogram was created. b. Define all significant variables c. Add comments describing the purpose of each key subsection of the subprogram. 2. Structure code to make it as readable as possible a. Use indentation b. The main program should act as an outline with calls to subprograms which actually perform desired operations Unix and C Page 7

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples Identifiers and Expressions CSE 130: Introduction to C Programming Spring 2005 Punctuation in C Statements are terminated with a ; Groups of statements are enclosed by curly braces: { and } Commas separate

More information

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C Character set in C We should use only the following characters in writing a C program. These characters can be combined to create C words. Alphabet: A, B, C, D.. Z, a, b, c, d..z Numeric digits: 0, 1,

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

C Programming Dr. Hasan Demirel

C Programming Dr. Hasan Demirel C How to Program, H. M. Deitel and P. J. Deitel, Prentice Hall, 5 th edition (3 rd edition or above is also OK). Introduction to C Programming Dr. Hasan Demirel Programming Languages There are three types

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 Basics of C Remark: Skim Chapters 1 through 6 of Deitel & Deitel. You will notice the following: C is (more or less) a subset of Java. (So, you are

More information

Introduction to C Programming S Y STEMS

Introduction to C Programming S Y STEMS Introduction to C Programming CS 40: INTRODUCTION TO U NIX A ND L I NUX O P E R AT ING S Y STEMS Objectives Introduce C programming, including what it is and what it contains, which includes: Command line

More information

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming INDEX 1) Introduction to C Programming a. What is C? b. Getting started with C 2) Data Types, Variables, Constants a. Constants, Variables and Keywords b. Types of Variables c. C Keyword d. Types of C

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Programming in C: Basics CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of variable We must declare the

More information

Programming for MSc Part I

Programming for MSc Part I Herbert Martin Dietze University of Buckingham herbert@the-little-red-haired-girl.org July 24, 2001 Abstract The course introduces the C programming language and fundamental software development techniques.

More information

Standard printing function in C is printf Prints everything numbers, strings, etc. May be complex to use. Standard C library is called libc

Standard printing function in C is printf Prints everything numbers, strings, etc. May be complex to use. Standard C library is called libc Arrays and Structs and Pointers, Oh My! Programming in C Input and output Using printf Standard input and output Pointers Arrays Structures Combining these things together Arrays and Structs and Pointers,

More information

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006 Basic C Syntax Comp-206 : Introduction to Software Systems Lecture 10 Alexandre Denault Computer Science McGill University Fall 2006 Next Week I'm away for the week. I'll still check my mails though. No

More information

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: IMPORTANT INSTRUCTIONS: 1. Question Paper in English and Hindi and Candidate can choose any one language. 2. In case of discrepancies in

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems, BSc (Hons) Mathematics & BSc (Hons) Software Engineering

BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems, BSc (Hons) Mathematics & BSc (Hons) Software Engineering BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems, BSc (Hons) Mathematics & BSc (Hons) Software Engineering Cohort: BCNS/07/FT- BIS/07/FT- BIS/06/FT -BM/07/FT BSE/07/FT/PT-

More information

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Lecture 03 Bits, Bytes and Data Types In this lecture Computer Languages Assembly Language The compiler Operating system Data and program instructions Bits, Bytes and Data Types ASCII table Data Types

More information

C AND C++ PROGRAMMING

C AND C++ PROGRAMMING C AND C++ PROGRAMMING Bharathidasan University A Courseware prepared by University Informatics Centre Part I - Programming in C Getting Started This courseware is intended to be an introduction to C programming

More information

C Programming, Chapter 1: C vs. Java, Types, Reading and Writing

C Programming, Chapter 1: C vs. Java, Types, Reading and Writing C Programming, Chapter 1: C vs. Java, Types, Reading and Writing T. Karvi August 2013 T. Karvi C Programming, Chapter 1: C vs. Java, Types, Reading and Writing August 2013 1 / 1 C and Java I Although the

More information

MIT Aurangabad FE Computer Engineering

MIT Aurangabad FE Computer Engineering MIT Aurangabad FE Computer Engineering Unit 1: Introduction to C 1. The symbol # is called a. Header file c. include b. Preprocessor d. semicolon 2. The size of integer number is limited to a. -32768 to

More information

C Primer. Fall Introduction C vs. Java... 1

C Primer. Fall Introduction C vs. Java... 1 CS 33 Intro Computer Systems Doeppner C Primer Fall 2016 Contents 1 Introduction 1 1.1 C vs. Java.......................................... 1 2 Functions 1 2.1 The main() Function....................................

More information

Going from Python to C

Going from Python to C Going from Python to C Darin Brezeale December 8, 2011 Python is a high-level, interpreted language. C has many of the same types of programming constructs as in Python: arrays, loops, conditionals, functions,

More information

C programming: exercise sheet L2-STUE (2011-2012)

C programming: exercise sheet L2-STUE (2011-2012) C programming: exercise sheet L2-STUE (2011-2012) Algorithms and Flowcharts Exercise 1: comparison Write the flowchart and associated algorithm that compare two numbers a and b. Exercise 2: 2 nd order

More information

PE1 Worksheet. 3) What are the three control structures for writing an algorithm in pseudocode?

PE1 Worksheet. 3) What are the three control structures for writing an algorithm in pseudocode? PE1 Worksheet Problem solving 1) What are the four stages of problem solving by programming? What shall be done in each stage? Stage 1: Stage 2: Stage 3: Stage 4: 2) What is the top-down design strategy

More information

CP Lab 2: Writing programs for simple arithmetic problems

CP Lab 2: Writing programs for simple arithmetic problems Computer Programming (CP) Lab 2, 2015/16 1 CP Lab 2: Writing programs for simple arithmetic problems Instructions The purpose of this Lab is to guide you through a series of simple programming problems,

More information

BHARATHIAR UNIVERSITY: COIMBATORE CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++ LANGUAGE

BHARATHIAR UNIVERSITY: COIMBATORE CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++ LANGUAGE Certificate in Advanced Programming - C++ Language Page 1 of 7 BHARATHIAR UNIVERSITY: COIMBATORE 641046 CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++

More information

Introduction to Programming Block Tutorial C/C++

Introduction to Programming Block Tutorial C/C++ Michael Bader Master s Program Computational Science and Engineering C/C++ Tutorial Overview From Maple to C Variables, Operators, Statements Functions: declaration, definition, parameters Arrays and Pointers

More information

CIS 190: C/C++ Programming. Lecture 1 Introduction and Getting Started

CIS 190: C/C++ Programming. Lecture 1 Introduction and Getting Started CIS 190: C/C++ Programming Lecture 1 Introduction and Getting Started This course will teach you the basics of C and C++ give you more programming experience be appropriate for majors and non-majors not

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

C Syntax and Semantics

C Syntax and Semantics C Syntax and Semantics 1 C Program Structure C Language Elements Preprocessor directives Function Header, and Function body Executable statements Reserved word, Standard identifiers, user defined identifiers

More information

Chapter 8. Arithmetic in C++

Chapter 8. Arithmetic in C++ Christian Jacob Chapter 8 Arithmetic in C++ 8.1 The C++ Vocabulary 8.2 Variables and Types 8.2.1 Data Objects 8.2.2 Variables 8.2.3 Declaration of Variables 8.3 Elementary C++ Data Types 8.3.1 Integers

More information

Overview of a C Program

Overview of a C Program Overview of a C Program Programming with C CSCI 112, Spring 2015 Patrick Donnelly Montana State University Programming with C (CSCI 112) Spring 2015 2 / 42 C Language Components Preprocessor Directives

More information

Programming Language: Syntax. Introduction to C Language Overview, variables, Operators, Statements

Programming Language: Syntax. Introduction to C Language Overview, variables, Operators, Statements Programming Language: Syntax Introduction to C Language Overview, variables, Operators, Statements Based on slides McGraw-Hill Additional material 2004/2005 Lewis/Martin Modified by Diana Palsetia Syntax

More information

GLG 490 Numerical Methods Intro to C Programming part 1

GLG 490 Numerical Methods Intro to C Programming part 1 Intro to C Programming part 1 In this course, we will learn the fundamentals of C programming. Entire courses can be taught on the subject, so we will restrict ourselves to the basics and learn enough

More information

The Basics of C Programming. Marshall Brain

The Basics of C Programming. Marshall Brain The Basics of C Programming Marshall Brain Last updated: October 30, 2013 Contents 1 C programming 1 What is C?................................. 2 The simplest C program, I........................ 2 Spacing

More information

Arrays. Arrays, Argument Passing, Promotion, Demotion

Arrays. Arrays, Argument Passing, Promotion, Demotion Arrays Arrays, Argument Passing, Promotion, Demotion Review Introduction to C C History Compiling C Identifiers Variables Declaration, Definition, Initialization Variable Types Logical Operators Control

More information

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays A First Book of C++ Chapter 2 Data Types, Declarations, and Displays Objectives In this chapter, you will learn about: Data Types Arithmetic Operators Variables and Declarations Common Programming Errors

More information

z = x + y * z / 4 % 2-1

z = x + y * z / 4 % 2-1 1.Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1? A. rem = 3.14 % 2.1; B. rem = modf(3.14, 2.1); C. rem = fmod(3.14, 2.1); D. Remainder cannot be obtain

More information

Reading Assignment. Main Program in C. K.N. King Chapter 2. K.N. King Chapter 3. K.N. King Chapter 4. K.N. King Chapter 7. Our first C program

Reading Assignment. Main Program in C. K.N. King Chapter 2. K.N. King Chapter 3. K.N. King Chapter 4. K.N. King Chapter 7. Our first C program Reading Assignment Main Program in C In C the main program is a function called main The body of the function is enclosed in left ( ) and right ( ) curly braces. K.N. King Chapter 2 K.N. King Chapter 3

More information

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer About The Tutorial C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.

More information

MPATE-GE 2618: C Programming for Music Technology. Unit 1.1

MPATE-GE 2618: C Programming for Music Technology. Unit 1.1 MPATE-GE 2618: C Programming for Music Technology Unit 1.1 What is an algorithm? An algorithm is a precise, unambiguous procedure for producing certain results (outputs) from given data (inputs). It is

More information

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu C / C++ and Unix Programming Materials adapted from Dan Hood and Dianna Xu 1 C and Unix Programming Today s goals ú History of C ú Basic types ú printf ú Arithmetic operations, types and casting ú Intro

More information

Chapter 2: Problem Solving Using C++

Chapter 2: Problem Solving Using C++ Chapter 2: Problem Solving Using C++ 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common

More information

C++ Keywords. If/else Selection Structure. Looping Control Structures. Switch Statements. Example Program

C++ Keywords. If/else Selection Structure. Looping Control Structures. Switch Statements. Example Program C++ Keywords There are many keywords in C++ that are not used in other languages. bool, const_cast, delete, dynamic_cast, const, enum, extern, register, sizeof, typedef, explicit, friend, inline, mutable,

More information

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment

More information

UNIT-1. C Programming & Data Structures. Introduction to Computers: Computing Environment: Types of Computing Environments:

UNIT-1. C Programming & Data Structures. Introduction to Computers: Computing Environment: Types of Computing Environments: Introduction to Computers: C Programming & Data Structures UNIT-1 A computer system consists of hardware and software. Computer hardware is the collection of physical elements that comprise a computer

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

OSMIC. CSoft ware. C Language manual. Rev Copyright COSMIC Software 1999, 2003 All rights reserved.

OSMIC. CSoft ware. C Language manual. Rev Copyright COSMIC Software 1999, 2003 All rights reserved. OSMIC CSoft ware C Language manual Rev. 1.1 Copyright COSMIC Software 1999, 2003 All rights reserved. Table of Contents Preface Chapter 1 Historical Introduction Chapter 2 C Language Overview C Files...2-1

More information

INTRODUCTION TO FLOWCHARTING

INTRODUCTION TO FLOWCHARTING CHAPTER 1 INTRODUCTION TO FLOWCHARTING 1.0 Objectives 1.1 Introduction 1.2 Flowcharts 1.3 Types of Flowcharts 1.3.1 Types of flowchart 1.3.2 System flowcharts 1.4 Flowchart Symbols 1.5 Advantages of Flowcharts

More information

Programming in C 1. Bharat Kinariwala Tep Dobry. 1 Copyright c1993 by B.Kinariwala and T. Dobry. All rights reserved.

Programming in C 1. Bharat Kinariwala Tep Dobry. 1 Copyright c1993 by B.Kinariwala and T. Dobry. All rights reserved. Programming in C 1 Bharat Kinariwala University ofhawai`i Tep Dobry University ofhawai`i January 5, 1993 1 Copyright c1993 by B.Kinariwala and T. Dobry. All rights reserved. Contents Table of Contents

More information

SYSTEMS PROGRAMMING C++ INTRODUCTION

SYSTEMS PROGRAMMING C++ INTRODUCTION Faculty of Computer Science / Institute of Systems Architecture / Operating Systems SYSTEMS PROGRAMMING C++ INTRODUCTION Alexander Warg WHY C++? C++ is the language that allows to express ideas from the

More information

198:211 Computer Architecture

198:211 Computer Architecture 198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book 1 Computer Architecture What do computers do? Manipulate stored

More information

C++ Programming Language

C++ Programming Language C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Birla Institute of Technology &Science, Pilani Computer Programming (CS F111) Second Semester Lab-3 (Introduction to C Programming Language)

Birla Institute of Technology &Science, Pilani Computer Programming (CS F111) Second Semester Lab-3 (Introduction to C Programming Language) Topics to be covered: 1. C Program structure and execution 2. Data type 3. Reading input and printing output 4. Expression 5. Operator precedency 6. Typecasting Birla Institute of Technology &Science,

More information

arrays C Programming Language - Arrays

arrays C Programming Language - Arrays arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)

More information

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :

More information

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands C Programming for Embedded Microcontrollers Warwick A. Smith Elektor International Media BV Postbus 11 6114ZG Susteren The Netherlands 3 the Table of Contents Introduction 11 Target Audience 11 What is

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with the basic components of a C++ program,

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

C++ Tutorial. Let s get to coding. W. Deconinck 1 V. Gray 2. Department of Physics College of William & Mary

C++ Tutorial. Let s get to coding. W. Deconinck 1 V. Gray 2. Department of Physics College of William & Mary C++ Tutorial Let s get to coding W. Deconinck 1 V. Gray 2 1 Assistant Professor Department of Physics College of William & Mary 2 Graduate Student Department of Physics College of William & Mary C++ Tutorial,

More information

Chapter 18 I/O in C. Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Chapter 18 I/O in C. Copyright 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 information

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 603 203 DEPARTMENT OF COMPUTER APPLICATIONS QUESTION BANK IN REVISED BLOOM S TAXONOMY

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 603 203 DEPARTMENT OF COMPUTER APPLICATIONS QUESTION BANK IN REVISED BLOOM S TAXONOMY ACADEMIC YEAR: 0 7 VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 0 0 SEMESTER: ODD BRANCH: MCA YEAR: I SEMESTER: I SUBJECT CODE AND NAME: MC70 Problem Solving and Programming NAME OF THE FACULTY

More information

OS Lab Tutorial 1. Linux System and Basic C Programming

OS Lab Tutorial 1. Linux System and Basic C Programming OS Lab Tutorial 1 Linux System and Basic C Programming Instructor: Cheng CSC 360 Tutorial Email: cchenv@uvic.ca Office Hour: ECS 561, Fridays 1:30-2:20 Today... Connect to machines in the Linux Lab, ECS242

More information

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++ Adjusted/Modified by Nicole Tobias Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types

More information

LAB 1 REPRESENTATION OF NUMBERS AND INTRODUCTION TO C

LAB 1 REPRESENTATION OF NUMBERS AND INTRODUCTION TO C LAB 1 REPRESENTATION OF NUMBERS AND INTRODUCTION TO C 1. LAB OBJECTIVE The objective of this lab is to review binary numbers and to review/introduce you to the C programming language and the MATLAB environment.

More information

TN203. Porting a Program to Dynamic C. Introduction

TN203. Porting a Program to Dynamic C. Introduction TN203 Porting a Program to Dynamic C Introduction Dynamic C has a number of improvements and differences compared to many other C compiler systems. This application note gives instructions and suggestions

More information

3) Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

3) Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging? Freshers Club Important 100 C Interview Questions & Answers 1) How do you construct an increment statement or decrement statement in C? There are actually two ways you can do this. One is to use the increment

More information

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011 6.096 Lab 1 Due: 7 January 1:30:00 September 0, 011 1 Additional Material 1.1 Constants A constant is an expressions with a fixed value. Kinds of constants: Literals: used to express particular values

More information

3.0 INTRODUCTION 3.1 OBJECTIVES

3.0 INTRODUCTION 3.1 OBJECTIVES Software UNIT 3 CONCEPT IN PROGRAMMING LANGUAGE Structure Page No. 3.0 Introduction 58 3.1 Objectives 58 3.2 Problem, Algorithm, Program and Programming Language 59 3.3 Concept of a Programming Language

More information

Chapter 4 C Program Control

Chapter 4 C Program Control Chapter 4 C Program Control Objectives of this chapter: Repetitions will be considered in greater detail for.. repetition do while repetition Also multiple selection switch case statement will be learned.

More information

C for Java Programmers

C for Java Programmers C for Java Programmers CS 414 / CS 415 Niranjan Nagarajan Department of Computer Science Cornell University niranjan@cs.cornell.edu Original Slides: Alin Dobra Why use C instead of Java Intermediate-level

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

Computer Programming Tutorial

Computer Programming Tutorial Computer Programming Tutorial COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Computer Prgramming Tutorial Computer programming is the act of writing computer

More information

A C# program structure About variables Predefined Data Types Flow Control Enumerations Arrays Namespaces The Main() method. Console IO Comments

A C# program structure About variables Predefined Data Types Flow Control Enumerations Arrays Namespaces The Main() method. Console IO Comments Basics of C# What are we going to study? A C# program structure About variables Predefined Data Types Flow Control Enumerations Arrays Namespaces The Main() method Compilation of C# program Console IO

More information

C Programming Lab. 1DT032: Advanced Computer Science Studies in Sweden 1DT086: Introduction to Studies in Embedded Systems Uppsala University

C Programming Lab. 1DT032: Advanced Computer Science Studies in Sweden 1DT086: Introduction to Studies in Embedded Systems Uppsala University C Programming Lab 1DT032: Advanced Computer Science Studies in Sweden 1DT086: Introduction to Studies in Embedded Systems Uppsala University September 3, 2015 Submitting Assignments, and Requirements for

More information

FEEG6002 - Applied Programming 5 - Tutorial Session

FEEG6002 - Applied Programming 5 - Tutorial Session FEEG6002 - Applied Programming 5 - Tutorial Session Sam Sinayoko 2015-10-30 1 / 38 Outline Objectives Two common bugs General comments on style String formatting Questions? Summary 2 / 38 Objectives Revise

More information

C Programming in Linux Environment

C Programming in Linux Environment C Programming in Linux Environment Srinivasulu Karasala V1.20 1 1. Computer and You When you sit in front of a computer and working on it, following sub systems are involved: You, as computer user Application

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

C A short introduction

C A short introduction About these lectures C A short introduction Stefan Johansson Department of Computing Science Umeå University Objectives Give a short introduction to C and the C programming environment in Linux/Unix Go

More information

Model Paper Computer Science Objective. Paper Code Time Allowed: 20 minutes

Model Paper Computer Science Objective. Paper Code Time Allowed: 20 minutes Note: This is Model Paper for guidance of students & teachers. Q. Model Paper Computer Science Objective Intermediate Part II ( th Class) Examination Session -4 and onward Total marks: 7 Paper Code Time

More information

C Syntax and the GCC Compiler

C Syntax and the GCC Compiler C Syntax and the GCC Compiler (what does mean: void (*(*f[])())()?) Emmanuel Fleury LaBRI, Université de Bordeaux, France September 7, 2015 Emmanuel Fleury (LaBRI, France) C

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Common Errors in C. David Chisnall. February 15, 2011

Common Errors in C. David Chisnall. February 15, 2011 Common Errors in C David Chisnall February 15, 2011 The C Preprocessor Runs before parsing Allows some metaprogramming Preprocessor Macros Are Not Functions The preprocessor performs token substitution

More information

12 INPUT AND OUTPUT OF DATA

12 INPUT AND OUTPUT OF DATA 12 INPUT AND OUTPUT OF DATA 12.1 INTRODUCTION In C language input and output of data is done by a collection of library functions like getchar, putchar, scanf, printf, gets and puts. These functions permit

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer About the Tutorial Computer programming is the act of writing computer programs, which are a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer.

More information

Standard C Input/Output. Output: printf() Table of Contents

Standard C Input/Output. Output: printf() Table of Contents Standard C Input/Output 1 Output: printf() 2 Table of Contents Output: printf( ) - syntax & sematics Output: printf( ) - examples Output: printf( ) - format control Screen / Printer Control Input: scanf(

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

GETTING STARTED WITH C++ C++ BASICS - 1 -

GETTING STARTED WITH C++ C++ BASICS - 1 - - 1 - GETTING STARTED WITH C++ Programming is a core activity in the process of performing tasks or solving problems with the aid of a computer. An idealised picture is: PROBLEM COMPUTER SOLUTION Unfortunately

More information

MPI and C-Language Seminars 2010

MPI and C-Language Seminars 2010 MPI and C-Language Seminars 2010 Seminar Plan (1/3) Aim: Introduce the C Programming Language. Plan to cover: Basic C, and programming techniques needed for HPC coursework. C-bindings for the Message Passing

More information

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR ODD/EVEN ACADEMICSEMESTER (2014-15) ASSIGNMENT / QUESTION BANK (2110003) [F.Y.B.E.

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR ODD/EVEN ACADEMICSEMESTER (2014-15) ASSIGNMENT / QUESTION BANK (2110003) [F.Y.B.E. SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR ODD/EVEN ACADEMICSEMESTER (2014-15) ASSIGNMENT / QUESTION BANK Subject: Computer Programming and Utilization (2110003) [F.Y.B.E.: ALL BRANCHES] Unit 1

More information

The if-statement. Simple and compound statements. The if-statement comes in two forms: Simple statements:

The if-statement. Simple and compound statements. The if-statement comes in two forms: Simple statements: 1 2 Simple and compound s The if- Simple s: E.g.: expression; Various jumps : break, goto, continue, return. k = a * p + 3; printf("k = %d\n", k); 1 + 2; ; The if- comes in two forms: or E.g.: if (expression)

More information

The char Data Type. Character and String Processing. Another Example /* Capitalize all lowercase letters */ while ((c = getchar())!

The char Data Type. Character and String Processing. Another Example /* Capitalize all lowercase letters */ while ((c = getchar())! Character and String Processing CSE 130: Introduction to C Programming Spring 2005 The char Data Type A char value can be thought of as either a character or a small integer printf( %d, a ); /* prints

More information

Lecture 3 C Programming Language

Lecture 3 C Programming Language Lecture 3 C Programming Language Summary of Lecture 3 streams error handling library functions break, continue, switch statements constants and macros C preprocessor (CPP) header files Streams Stdin, stdout

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

C programming. Intro to syntax & basic operations

C programming. Intro to syntax & basic operations C programming Intro to syntax & basic operations Example 1: simple calculation with I/O Program, line by line Line 1: preprocessor directive; used to incorporate code from existing library not actually

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Format String Vulnerability. printf ( user input );

Format String Vulnerability. printf ( user input ); Lecture Notes (Syracuse University) Format String Vulnerability: 1 Format String Vulnerability printf ( user input ); The above statement is quite common in C programs. In the lecture, we will find out

More information