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



Similar documents
ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

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

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

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

C PROGRAMMING FOR MATHEMATICAL COMPUTING

Informatica e Sistemi in Tempo Reale

Introduction to Java

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

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

C++ Programming Language

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

C++ INTERVIEW QUESTIONS

1 Abstract Data Types Information Hiding

Pemrograman Dasar. Basic Elements Of Java

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

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

So far we have considered only numeric processing, i.e. processing of numeric data represented

Computer Programming Tutorial

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Tutorial on C Language Programming

Chapter 13 Storage classes

The C Programming Language course syllabus associate level

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Chapter 2: Elements of Java

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

J a v a Quiz (Unit 3, Test 0 Practice)

Stacks. Linear data structures

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

C++ Language Tutorial

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

System Calls and Standard I/O

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

Illustration 1: Diagram of program function and data flow

Answers to Review Questions Chapter 7

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

13 Classes & Objects with Constructors/Destructors

Programming Microcontrollers in C

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

C Interview Questions

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

MISRA-C:2012 Standards Model Summary for C / C++

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Fundamentals of Programming

El Dorado Union High School District Educational Services

C++FA 5.1 PRACTICE MID-TERM EXAM

Install Java Development Kit (JDK) 1.8

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Chapter 1 Java Program Design and Development

CS 241 Data Organization Coding Standards

Comp151. Definitions & Declarations

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Introduction to Programming II Winter, 2014 Assignment 2

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

How To Write Portable Programs In C

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Chapter One Introduction to Programming

Introduction to Java. CS 3: Computer Programming in Java

Object-Oriented Programming in Java

Lecture 22: C Programming 4 Embedded Systems

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

arrays C Programming Language - Arrays

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

An Incomplete C++ Primer. University of Wyoming MA 5310

Building Java Programs

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.

Java Interview Questions and Answers

/* File: blkcopy.c. size_t n

5 Arrays and Pointers

VB.NET Programming Fundamentals

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

ECE 122. Engineering Problem Solving with Java

Module 816. File Management in C. M. Campbell 1993 Deakin University

3/13/2012. Writing Simple C Programs. ESc101: Decision making using if-else and switch statements. Writing Simple C Programs

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

The programming language C. sws1 1

C STYLE GUIDE AUGUST 1994 SOFTWARE ENGINEERING LABORATORY SERIES SEL National Aeronautics and Space Administration

Passing 1D arrays to functions.

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

Computer Science 2nd Year Solved Exercise. Programs 3/4/2013. Aumir Shabbir Pakistan School & College Muscat. Important. Chapter # 3.

Chapter 2 Introduction to Java programming

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Basics of I/O Streams and File I/O

Embedded C Programming

Introduction to Programming

Object Oriented Software Design II

Object Oriented Software Design

C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;

An Overview of Java. overview-1

Conditionals (with solutions)

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Programming Languages CIS 443

Programming languages C

C Programming Tutorial

csce4313 Programming Languages Scanner (pass/fail)

Transcription:

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, 2, 3,4,5,6,7,8,9 Special Characters: + * / %? &! = \ [ ] ( ) { } < > @ # ^. _, : ; ~ Words in C We can divide the words in C into three groups: 1. Constants 2. Variables 3. Reserved words or key words. 4. Constants Constant represent fixed values. That means, their value will not change in the program. For example, the numbers used by us will come under constants as their value will not change. Similarly, names of persons will also come under constants. 5, -125, 255 are called Integer constant. 12.5, -3.14159 are called real constants. A, M, S are called Character constants. Rajesh, Software are called string constants. In the preceding example we should note that the character constants should be enclose in single quotes and the string should be enclosed in double quotes. 2. Variables

Variables represent words which store varying (changing) values. For example, Int x; Here, x is the name of a variable whose type is int. It means we can store an integer number in this variable x. Internally, a variable represents a memory location. So, if we store an integer in a variable, then we should understand that it is store in a memory location. If we store an integer number in a variable, then it is called Integer Type variable. If we store a real number in a variable, then it is called Float Type variable. If we store a single character in a variable, then it is called Character Type variable. int empcode; float emp_sal; char gender; In the preceding examples, empcode, emp_sal and gender are the names of the variables. We can use these variables to store values as shown here: empcode = 1001; emp_sal = 7890.50; gender = M ; Please observe that in the empcode variable, we are storing 1001 which is an Integer constant. In emp_sal variable, we are storing 7890.50 which is a Real constant. In gender variable, we are storing M which is Character constant. A string represents a group of characters. Strings are character type array in C. to store a string, we need a characters type array. We will learn about character array in a later chapter. While writing the names of variables, we should start the name with an alphabet. Generally, we should not use any blanks or any special characters in the variable

names, except underscore symbol (_). The main point to remember is that a variable should be declare first in a C program only once. After that it can be used at any time. For example, int num; Here we are declaring the variable num as int type. After declaring the variable, we can use it. For example, now we can store integer number into the variable, as num = 100; It is not possible to use a variable without declaring it. 3. Reserved words Variable names are in our hands. We can give any names we wish. But there are some words which cannot be used as variables. They are used in some special meaning only. They are called reserved words or key words. There are a total of 32 Reserved words in C which are shown here: auto double int struct Break else long switch Case enum register typedef Char extern return union Const float sizeof unsigned Continue for short void Default goto signed volatile Do if static while

C Statements There are two type of statements input statement and output statements. The data given to a program is called input and the result given by the program is called output. To provide data to a program, we need input statement. Similarly, to display the result, we use output statement. We should understand one important point in C. To do any work we need a function in C. A function can be imagined as a set of statements aimed to perform a task. There are various functions provided in the form of header file in C library. See the figure 2 C standard Library Header Files Functions Figure 2: C standard library contains header files and functions. If want to perform any task, we need a function. So, in writing any statements, we would generally function. In input and output statements also, we need a function. The following table gives the list of basic input and output functions which are available in the part of the header file; stdio.h, i.e. standard input output header file. Input Functions Output functions getchar( ) putchar( ) gets( ) puts( ) scanf( ) printf( )

Table 1: Basic Input and Output functions in stdio.h. getchar() function Using getchar() function, we can give a single character as input. getchar() function takes the character and store it into a variable. ch= getchar(); Here, getchar() accepts a single character from the keyboard and stores into the variable ch. Here ch represents a character type variable. We should note that any function name in C end with a pair of simple braces, for example: getch() or putch(). putch() function Using putch() function, we can display a single character as output on the monitor. putch(ch); Here, putch() function, we can taking a variable ch and it sends the content of that variable to the monitor. putchar( A );

Here, putchar() will display the character A directly on the monitor. Program Program 1: Let us write a program to understand how to input a single character from the keyboard and how to display the same character on the monitor. /* To accept and display a single character */ #include<stdio.h> void main() { char ch; ch = getch(); putch(ch); } Let understand this program clearly. The first line represents comment line. /* To accept and display a single character */

Comments describe the aim of a program or any statement(s) in the program. Comment are written inside /* and */. Comments are not executed by the compiler. So they are called non executable statements. They are for increasing the readability (understandability) of the program. Important interview Question Can you nest a comment inside anther comment in C? No, it is not possible to write a comment inside another comment. # include<stdio.h> This represents an instruction to the C compiler to include the header file: stdio.h. Since we want to use getch() and putch() functions in the program, and those functions are available in stdio.h, it is compulsory to include this header file/ then only we can use any of the functions from that header file in our program. void main() Here, main() is the function name from where a C program execution starts. Before this main(), we can see void. It means no value. So, main() function will no return any value. It simply executes and display the result. In every C program, we should write this main() function.

Important Interview Question What is returned by main() function, by default? main() function or any other function in C by default returns an integer type value. By writing void before main() function, we are indicating that main() function is not returning any value. If we do not write void before main(), then it returns an integer value. After main() function, we should write { which represent the beginning of the main() function and } which represent ending of the function. The statements inside this function are executed by the compiler. char ch; Here, ch is a variable declare as char type. So, it is possible to store a single character in ch. ch = getch(); Here, getch() function waits for input of a single character. When we enter a character from the keyboard, it reads it and then stores it into the variable ch. Storage is done by the symbol = which is called assignment operator. putchar(ch);

Here, putchar() function is displaying the content of ch on the monitor. Important Interview Question What is the use of the main() function in C? main() function is the starting point of execution of a C program. Every C program should have a main() function. gets() function This function is useful to accept a string from the keyboard and store it into a variable. A string represents a group of characters. gets(str); In this statement, gets() function will accept a string from the keyboard and stores into the variable str. puts() function this function displays a string on the monitor. puts(str)