C-Language Tutorial. Apple Macintosh system software was formerly written in Pascal, but is now almost always written in C.

Similar documents
Fundamentals of C Programming

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Fundamental of C programming. - Ompal Singh

Preview from Notesale.co.uk Page 6 of 52

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

Chapter 2. Basics of Program Writing

Presented By : Gaurav Juneja

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

EL2310 Scientific Programming

Fundamentals of Programming Session 4

Computers Programming Course 5. Iulian Năstac

Chapter 2: Programming Concepts

Introduction to Computing Lecture 01: Introduction to C

EL2310 Scientific Programming

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

C library = Header files + Reserved words + main method

COMPUTER PROGRAMMING LOOPS

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

SDKs - Eclipse. SENG 403, Tutorial 2

AP Computer Science Summer Assignment (updated 5/29/2018) DUE : Sept. 4, 2018

History of C Programming Language. Why Name C was given to Language? Summary of C Programming Language History. C Programming Language Timeline:

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

Data Types and Variables in C language

CS 177 Recitation. Week 1 Intro to Java

1.1 Introduction to C Language. Department of CSE

String Instructions In C Programming Language Using

Chapter 1 & 2 Introduction to C Language

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

COMP s1 Lecture 1

Introduction to C An overview of the programming language C, syntax, data types and input/output

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

Software and Programming 1

edunepal_info

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

Programming. Data Structure

Chapter 1: A First Program Using C#

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

You should see something like this, called the prompt :

Programming for Engineers: Getting Started

Java: Comment Text. Introduction. Concepts

Fundamentals of Programming. By Budditha Hettige

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN. Week 12/02/ /02/2007 Lecture Notes:

Algorithms and Programming I. Lecture#12 Spring 2015

PROGRAMMING FUNDAMENTALS

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

Master of Computer Applications COMPUTER PROGRAMMING USING C

Section 2.2 Your First Program in Java: Printing a Line of Text

Getting started with Java

printf( Please enter another number: ); scanf( %d, &num2);

KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur

Course Outline. Introduction to java

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Programming. Syntax and Semantics

Kickstart Intro to Java Part I

Lecture 1 - Introduction (Class Notes)

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Chapter 1 Introduction to Computers, Programs, and Java

ANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013

Introduction to MATLAB

Binghamton University. CS-120 Summer Introduction to C. Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Technical Questions. Q 1) What are the key features in C programming language?

Chapter 1 INTRODUCTION

Why C++? C vs. C Design goals of C++ C vs. C++ - 2

C: How to Program. Week /Mar/05

Introduction: The Unix shell and C programming

Variables. Store information needed by the program

Informática Ingeniería en Electrónica y Automática Industrial

Hands-On Ethical Hacking and Network Defense 2 nd edition

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

Review Ch 5 static Multiple Choice Test Creating Class Methods

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CS133 C Programming. Instructor: Jialiang Lu Office: Information Center 703

Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

C Language, Token, Keywords, Constant, variable

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

Copyright. Trademarks Attachmate Corporation. All rights reserved. USA Patents Pending. WRQ ReflectionVisual Basic User Guide

Lecture 1: Preliminaries

Introduction to C Language

Chapter 2 - Introduction to C Programming

Certified Core Java Developer VS-1036

Introduction to the C Programming Language

CST8152 Compilers Creating a C Language Console Project with Microsoft Visual Studio.Net 2003

AMCAT Automata Coding Sample Questions And Answers

Lesson 01 Introduction

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

PROGRAMMAZIONE I A.A. 2017/2018

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

Transcription:

C-Language Tutorial Introduction The C programming language was originally developed by Dennis Ritchie of Bell Laboratories,and was designed to run on a UNIX operating system Although it was originally intended to run under UNIX, there was a great interest in running it on the IBM PC and compatibles,and other systems. It is an excellent language for this environment because of the simplicity of expression, the compactness of the code, and the wide range of applicability. It allows the programmer a wide range of operations from high level down to a very low level approaching the level of assembly language. There seems to be no limit to the flexibility available. Programming in C is a tremendous asset in those areas where you may want to use Assembly Language, but would rather keep it a simple to write and easy to maintain program. Approximately 75 percent of all new commercial programs introduced for the IBM PC have been written in C, and the percentage is probably growing. Apple Macintosh system software was formerly written in Pascal, but is now almost always written in C. There was no official standard for the C language, but the American National Standards Institute (ANSI) has developed a standard for the language,so it will follow rigid rules. Even though the C language enjoys a good record when programs are transported from one implementation to another, there are differences in compilers, as you will find any time you try to use another compiler.

Over the years several programming languages have been developed to help the programmers to get the computer to performed various tasks. While the programming languages have been varied in terms of key words they have, and the way in which they are written, the basic approach to writing a program has remained more or less the same. For Example: Consider the code written below using three different languages like C,BASIC,and Java * Code Snippet Written In C * * Code Snippet Written In BASIC * #include<stdio.h> 10 Input name$ void main() 20 Print Hello,name$ { 30 END Char name[15]; * Code Snippet Written In Java * Printf( Enter Name : ); Scanf( %s,&name); Printf( Hello %s,name); } Class Hello { Public static void main(string args[]) { String name; System.in.readln(name); System.out.println( Hello +name); } } 2

All the three snippets of code achieve the same task-that of accepting the users name and displaying a welcome message. Note,however,that although the syntax (the way in which the code is written using the keywords of a specific language) differs from one language to the other the logic (steps Followed) behind each of the programs remains the same. The primary reason for choosing C language for learning programming fundamentals is because the structure of C and a lot of keywords in it resemble the ones in java 3

GETTING STARTED WITH C Let us start with the C language. Following are the steps involved in writing a program using C-language 1) Invoking The Turbo C++ editor 2) Writing a new program 3) Saving the program using the given editor 4) Building the program 5) Quitting from turbo c and Executing the program NOTE: You can also write a program in c using Borland C editor 4

STEP 1-Invoking Turbo C++ Editor Click on start, go to run and type cmd to invoke the MS-DOS prompt Locate the directory where the turbo C++ editor is installed (i.e. C,D,etc) Enter the path to invoke the turbo c++ editor as shown in the figure given below 5

The Turbo C++ editor would look as shown in figure given blow 6

STEP 2-Writing a New Program To write a new program, follow the steps given below 1) Press the combination <Alt+F> to invoke the menu File This displays the submenu options. 2) Press down the key to select the option, New. Refer Figure below 7

3) Press <Enter> This opens a new file refer figure below The default name NONAME00.CPP is displayed in the title bar as shown below 4) Now you can type the required code in the Edit Window NOTE: C programs are case sensitive. the instructions need to be always in lower case 8

STEP 3- Saving the Program To save the program, follow the steps given below 5) Press the key combination <Alt+F> to invoke the menu File. 6) Press the down arrow key to select the option Save As... 7) Press <Enter> This displays the dialog box, Save File as Refer figure given below. 9

8) Type a valid filename in the Save File as text box (In this example, we use FIRST as the filename). Refer figure given below 9) Press<Enter> Note that FIRST.C (the name of the file) is displayed in the title bar 10

STEP-4 Building the Program After writing the program, before it can be executed, the program has to go through two stages: Compiling Process- changes the program code written in C to the code that can be understand by the machine 1. 2. Linking Process- stores the machine code in an executable file format The two stages compiling and linking are combined in the build process. To build the program, follow these steps 10) Press the key combination <Alt+C> to invoke the menu Compile This displays its sub menu options as shown in the figure below Continued 11

11) Press the down arrow key to select the option, Build all Selecting this option will compile and link the C program in one go 12

12) Press <Enter> This builds the program. On success, the Linking message box will display the message Success: Press any key to continue as shown in the figure below Notice that the name of the EXE file created by the build process is the same as that of the C file. In our case, the resultant EXE file created is called FIRST.exe 13

In C, when you build a program, the errors and warnings are displayed in a separate window at the bottom. Warnings only point out to inefficiency in the code. Therefore, if any warnings are displayed,the code can still be executed. However,in the case of errors, they have to solved before the program can be executed In this program, the warnings and errors are displayed in a separate window as shown in the given figure 13) Press <Enter> 14

STEP 5- Quitting the Program and Executing the Program To quit turbo c follow these steps 14) Press the key combination <Alt+F> to invoke the menu File 15) Press the down arrow key to select the option Quit 16) Press <Enter> This will take you back to the Dos Prompt To Execute the program follow these steps 1. 2. Press the key combination <Alt+R> to invoke the menu Run Press <Enter> Continued 15

16

Working With C Program Session 1: Concepts- Basic Programming Session 2: Working with Operators and Conditions Session 3: Working with Iteration Constructs Session 4: Using Functions Session 5: Working with Arrays and Structures Session 6: Pointers In C 17

Session 1:Basic Programming Concepts This session includes the basic programming concepts such as What is variable and how it is used in C language What are datatypes and their types used in C language A sample C program Errors in C language Other Important Programming Concepts 18

Defining Variables In C Language A variable can be defined as a named location in memory where a particular value is stored Variables allow us to provide a meaningful name for some locations in memory by which we can access this location. For Example: Consider a program where we are going to accept two numbers and display their sum. The pseudo code for the same is provided in the given example BEGIN DISPLAY Enter 2 Numbers INPUT A,B C=A+B Display C END Pseudo Code Pseudo Code Pseudo code is not the actual code as the name suggests (pseudo=false) but a method which uses a certain standard set of words which makes it resemble code Unlike the actual code, pseudo code cannot be compiled or run 19

Guidelines To Be Followed While Naming Variables Variable names must begin with an alphabet. The First Character can be followed by a sequence of alphanumeric characters and can also include special characters such as underscore. Proper names should be avoided while naming variables. A variable name should be very meaningful and descriptive. It should describe the kind of data in it. Letters such as O and I should be avoided in variable name, as these can be confused with similar characters such as 0 and 1. While naming variables we need to ensure that we do not use one of the keywords as a variable name. 20