C is a programming language created in 1972 at Bell Labs to design the UNIX operating system. It spread quickly due to its power and portability. In 1989, ANSI standardized C to resolve issues from different compiler versions. C is an excellent choice for first programs due to its efficiency, flexibility, portability, and ability to write system software and packages. It has a rich set of data types, operators, and functions and allows extending functionality with custom functions. Variables are names for memory locations that can hold different data types and values.
The document provides an introduction to C programming, covering topics such as what a program is, programming languages, the history of C, and the development stages of a C program. It discusses the key components of a C program including preprocessing directives, the main function, and program layout. Examples are provided to illustrate C code structure and the use of variables, keywords, operators, input/output functions, and formatting output with printf.
C programs are composed of six types of tokens: keywords, identifiers, constants, strings, special symbols, and operators. Keywords are reserved words that serve as building blocks for statements and cannot be used as names. Identifiers name variables, functions, and arrays and must begin with a letter. Constants represent fixed values and come in numeric, character, and string forms. Special symbols include braces, parentheses, and brackets that indicate code blocks, function calls, and arrays. Operators perform arithmetic, assignment, comparison, logic, and other operations.
This document discusses variables in C programming. It explains that variables are names that refer to memory locations where values can be stored and changed during program execution. It provides the syntax for declaring variables using different data types like int, float, double, and char. Rules for variable names are also outlined, such as starting with a letter or underscore and avoiding reserved words.
The document provides an overview of the C programming language. It discusses the origins and development of C from earlier languages like ALGOL and BCPL. It describes key features of C like data types, variables, constants, and operators. It also provides a basic Hello World program example and explains the process of compiling and executing a C program.
The document discusses the process from compiling source code to executing a program. It covers preprocessing, compilation, assembly, linking, and the ELF file format. Preprocessing handles macros and conditionals. Compilation translates to assembly code. Assembly generates machine code. Linking combines object files and resolves symbols statically or dynamically using libraries. The ELF file format organizes machine code and data into sections in the executable.
Type casting is converting a variable from one data type to another. It is done explicitly using a cast operator like (type_name). It is best to cast to a higher data type to avoid data loss as casting to a lower type may truncate the value. There are two types of casting in C - implicit casting which happens automatically during assignment, and explicit casting which requires a cast operator. Implicit casting is done when assigning a value to a compatible type while explicit casting is needed when types are incompatible.
C Tokens, Escape sequence, Delimiters, Variables, Data types, Constants/ Literals, Expressions, Statements and Comments
https://github.com/ashim888/csit-c
The document provides an introduction to C programming, covering topics such as what a program is, programming languages, the history of C, and the development stages of a C program. It discusses the key components of a C program including preprocessing directives, the main function, and program layout. Examples are provided to illustrate C code structure and the use of variables, keywords, operators, input/output functions, and formatting output with printf.
C programs are composed of six types of tokens: keywords, identifiers, constants, strings, special symbols, and operators. Keywords are reserved words that serve as building blocks for statements and cannot be used as names. Identifiers name variables, functions, and arrays and must begin with a letter. Constants represent fixed values and come in numeric, character, and string forms. Special symbols include braces, parentheses, and brackets that indicate code blocks, function calls, and arrays. Operators perform arithmetic, assignment, comparison, logic, and other operations.
This document discusses variables in C programming. It explains that variables are names that refer to memory locations where values can be stored and changed during program execution. It provides the syntax for declaring variables using different data types like int, float, double, and char. Rules for variable names are also outlined, such as starting with a letter or underscore and avoiding reserved words.
The document provides an overview of the C programming language. It discusses the origins and development of C from earlier languages like ALGOL and BCPL. It describes key features of C like data types, variables, constants, and operators. It also provides a basic Hello World program example and explains the process of compiling and executing a C program.
The document discusses the process from compiling source code to executing a program. It covers preprocessing, compilation, assembly, linking, and the ELF file format. Preprocessing handles macros and conditionals. Compilation translates to assembly code. Assembly generates machine code. Linking combines object files and resolves symbols statically or dynamically using libraries. The ELF file format organizes machine code and data into sections in the executable.
Type casting is converting a variable from one data type to another. It is done explicitly using a cast operator like (type_name). It is best to cast to a higher data type to avoid data loss as casting to a lower type may truncate the value. There are two types of casting in C - implicit casting which happens automatically during assignment, and explicit casting which requires a cast operator. Implicit casting is done when assigning a value to a compatible type while explicit casting is needed when types are incompatible.
C Tokens, Escape sequence, Delimiters, Variables, Data types, Constants/ Literals, Expressions, Statements and Comments
https://github.com/ashim888/csit-c
Programs transform input data into output data using programming languages that support different data types and operations on those types. A data type specifies a set of values and operations on those values and is used to declare variables, return values, and function parameters. Identifiers refer to data types, variables, and functions and have specific naming rules. Common built-in data types include integers, characters, floating points, pointers, arrays, strings, and structures.
The document discusses dynamic memory allocation in C. It describes the four main functions for dynamic allocation - malloc(), calloc(), free(), and realloc(). malloc() allocates a block of memory of a specified size and returns a pointer. calloc() allocates multiple blocks of memory and initializes them to zero. free() releases previously allocated memory. realloc() changes the size of previously allocated memory. The document provides examples of using each function.
C language is a widely used, mid-level programming language that provides features like simplicity, portability, structured programming, rich libraries, memory management, pointers, recursion, and extensibility. It allows breaking programs into parts using functions, supports dynamic memory allocation using free(), and provides built-in data types like integer, floating point, character, arrays, pointers, structures, unions, enums, and void.
C Programming/Strings. A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '-' . So, a string with the contents, say, "abc" has four characters: 'a' , 'b' , 'c' , and the terminating null character.
The document discusses various C programming concepts like algorithms, flowcharts, tokens, data types, operators, functions, and hardware components of a computer. It includes questions and answers on these topics. Key points covered are definition of algorithm and flowchart, different types of tokens in C, differences between while and do-while loops, definition of software and its types, and examples of standard header files.
A file is a collection of related data that a computer treats as a single unit. Files allow data to be stored permanently even when the computer is shut down. C uses the FILE structure to store attributes of a file. Files allow for flexible data storage and retrieval of large data volumes like experimental results. Key file operations in C include opening, reading, writing, and closing files. Functions like fopen(), fread(), fwrite(), fclose() perform these operations.
The document discusses structures in C programming. It defines a structure as a user-defined data type that allows combining different data types under a single name. Structures are used to represent records with multiple attributes. The document explains how to declare and define structures with tags, and access structure members using dot and pointer operators. It provides an example of a nested structure and a program demonstrating the use of functions and pointers with structures.
1. A string is a one-dimensional array of characters terminated by a null character. Strings can be initialized during compilation or at runtime.
2. Common string functions like scanf(), gets(), getchar() are used to input strings while printf(), puts(), putchar() are used to output strings.
3. Library functions like strcpy(), strcat(), strcmp(), strlen() allow manipulation of strings like copying, concatenation, comparison and finding length.
Operators and expressions in c languagetanmaymodi4
what is operator in c language
uses of operator in c language
syatax of operator in c language
program of operator in c language
what is expressions in c language
use of expressions in c language
syantax of expressions in c language
- C is a commonly used language for embedded systems that is portable, produces efficient code, and uses a fairly concise syntax.
- It was developed in the late 1960s and early 1970s and was influenced by the B programming language.
- C uses basic data types, functions, expressions, statements, and other constructs to provide powerful yet flexible programming capabilities while using relatively little memory.
The document provides an introduction to the C programming language, including its history, features, character sets, tokens, data types, operators, and the basic structure of a C program. It discusses key concepts such as variables, constants, comments, functions, input/output, and how to compile and execute a C program.
This document provides an overview of common string functions in C including strcmp(), strcat(), strcpy(), and strlen(). It defines each function, explains what it is used for, provides the syntax, and includes examples of how each string function works in C code. Overall, the document is a tutorial on the most common string manipulation functions available in the standard C string library.
Structures in C allow grouping of different data types under a single name for convenient handling. A structure is declared using the typedef statement, specifying the structure name and members. Structures can be nested by including one structure as a member of another. Arrays of structures and pointers to structures can also be declared. Structures are commonly used with functions to organize related data.
Union in C allows defining a data type that contains multiple members of different data types that share the same memory location. The size of the memory allocated for a union is equal to the size of its largest member. Only one member can be accessed at a time since they share the same memory location. Accessing different members can corrupt the values stored as the memory is shared.
basic of desicion control statement in pythonnitamhaske
it consists if-else, nested if, if-elif-else, for loop, while loop with flowchart and examples. also continue ,pass and break statement.
and else with for and while loop
File handling in C allows programs to perform operations on files stored on the local file system such as creation, opening, reading, writing and deletion of files. Common file handling functions include fopen() to open a file, fprintf() and fscanf() to write and read from files, fputc() and fgetc() to write and read single characters, and fclose() to close files. Binary files store data directly from memory to disk and allow for random access of records using functions like fseek(), ftell() and rewind(). Command line arguments can be accessed in the main() function through the argc and argv[] parameters.
Strings are arrays of characters that are null-terminated. They can be manipulated using functions like strlen(), strcpy(), strcat(), and strcmp(). The document discusses initializing and reading strings, passing strings to functions, and using string handling functions to perform operations like copying, concatenating, comparing, and reversing strings. It also describes arrays of strings, which are 2D character arrays used to store multiple strings. Examples are provided to demonstrate reading and sorting arrays of strings.
The document outlines the structure of a C program, including documentation and header file sections, global variable declarations, the main function, user-defined functions, and comment lines. It notes that C programs typically include header files with file extensions of .h, global variables defined outside functions that can be accessed throughout the program, and that program execution starts and ends in the main function.
C is a programming language created by Dennis Ritchie at Bell Labs in 1972 to develop the UNIX operating system. It quickly became popular due to its efficiency, flexibility, and portability. In 1989, ANSI standardized C to promote consistency, and it has since become one of the most widely used programming languages. Variables in C must be declared before use and can be numeric like integers and floats, or character strings. Variable names follow specific rules and types must be specified in declarations.
C programming Training in Ambala ! Batra Computer Centrejatin batra
Batra Computer Centre is An ISO certified 9001:2008 training Centre in Ambala.
We Provide C Programming Training in Ambala. BATRA COMPUTER CENTRE provides best training in C, C++, S.E.O, Web Designing, Web Development and So many other courses are available.
Programs transform input data into output data using programming languages that support different data types and operations on those types. A data type specifies a set of values and operations on those values and is used to declare variables, return values, and function parameters. Identifiers refer to data types, variables, and functions and have specific naming rules. Common built-in data types include integers, characters, floating points, pointers, arrays, strings, and structures.
The document discusses dynamic memory allocation in C. It describes the four main functions for dynamic allocation - malloc(), calloc(), free(), and realloc(). malloc() allocates a block of memory of a specified size and returns a pointer. calloc() allocates multiple blocks of memory and initializes them to zero. free() releases previously allocated memory. realloc() changes the size of previously allocated memory. The document provides examples of using each function.
C language is a widely used, mid-level programming language that provides features like simplicity, portability, structured programming, rich libraries, memory management, pointers, recursion, and extensibility. It allows breaking programs into parts using functions, supports dynamic memory allocation using free(), and provides built-in data types like integer, floating point, character, arrays, pointers, structures, unions, enums, and void.
C Programming/Strings. A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '-' . So, a string with the contents, say, "abc" has four characters: 'a' , 'b' , 'c' , and the terminating null character.
The document discusses various C programming concepts like algorithms, flowcharts, tokens, data types, operators, functions, and hardware components of a computer. It includes questions and answers on these topics. Key points covered are definition of algorithm and flowchart, different types of tokens in C, differences between while and do-while loops, definition of software and its types, and examples of standard header files.
A file is a collection of related data that a computer treats as a single unit. Files allow data to be stored permanently even when the computer is shut down. C uses the FILE structure to store attributes of a file. Files allow for flexible data storage and retrieval of large data volumes like experimental results. Key file operations in C include opening, reading, writing, and closing files. Functions like fopen(), fread(), fwrite(), fclose() perform these operations.
The document discusses structures in C programming. It defines a structure as a user-defined data type that allows combining different data types under a single name. Structures are used to represent records with multiple attributes. The document explains how to declare and define structures with tags, and access structure members using dot and pointer operators. It provides an example of a nested structure and a program demonstrating the use of functions and pointers with structures.
1. A string is a one-dimensional array of characters terminated by a null character. Strings can be initialized during compilation or at runtime.
2. Common string functions like scanf(), gets(), getchar() are used to input strings while printf(), puts(), putchar() are used to output strings.
3. Library functions like strcpy(), strcat(), strcmp(), strlen() allow manipulation of strings like copying, concatenation, comparison and finding length.
Operators and expressions in c languagetanmaymodi4
what is operator in c language
uses of operator in c language
syatax of operator in c language
program of operator in c language
what is expressions in c language
use of expressions in c language
syantax of expressions in c language
- C is a commonly used language for embedded systems that is portable, produces efficient code, and uses a fairly concise syntax.
- It was developed in the late 1960s and early 1970s and was influenced by the B programming language.
- C uses basic data types, functions, expressions, statements, and other constructs to provide powerful yet flexible programming capabilities while using relatively little memory.
The document provides an introduction to the C programming language, including its history, features, character sets, tokens, data types, operators, and the basic structure of a C program. It discusses key concepts such as variables, constants, comments, functions, input/output, and how to compile and execute a C program.
This document provides an overview of common string functions in C including strcmp(), strcat(), strcpy(), and strlen(). It defines each function, explains what it is used for, provides the syntax, and includes examples of how each string function works in C code. Overall, the document is a tutorial on the most common string manipulation functions available in the standard C string library.
Structures in C allow grouping of different data types under a single name for convenient handling. A structure is declared using the typedef statement, specifying the structure name and members. Structures can be nested by including one structure as a member of another. Arrays of structures and pointers to structures can also be declared. Structures are commonly used with functions to organize related data.
Union in C allows defining a data type that contains multiple members of different data types that share the same memory location. The size of the memory allocated for a union is equal to the size of its largest member. Only one member can be accessed at a time since they share the same memory location. Accessing different members can corrupt the values stored as the memory is shared.
basic of desicion control statement in pythonnitamhaske
it consists if-else, nested if, if-elif-else, for loop, while loop with flowchart and examples. also continue ,pass and break statement.
and else with for and while loop
File handling in C allows programs to perform operations on files stored on the local file system such as creation, opening, reading, writing and deletion of files. Common file handling functions include fopen() to open a file, fprintf() and fscanf() to write and read from files, fputc() and fgetc() to write and read single characters, and fclose() to close files. Binary files store data directly from memory to disk and allow for random access of records using functions like fseek(), ftell() and rewind(). Command line arguments can be accessed in the main() function through the argc and argv[] parameters.
Strings are arrays of characters that are null-terminated. They can be manipulated using functions like strlen(), strcpy(), strcat(), and strcmp(). The document discusses initializing and reading strings, passing strings to functions, and using string handling functions to perform operations like copying, concatenating, comparing, and reversing strings. It also describes arrays of strings, which are 2D character arrays used to store multiple strings. Examples are provided to demonstrate reading and sorting arrays of strings.
The document outlines the structure of a C program, including documentation and header file sections, global variable declarations, the main function, user-defined functions, and comment lines. It notes that C programs typically include header files with file extensions of .h, global variables defined outside functions that can be accessed throughout the program, and that program execution starts and ends in the main function.
C is a programming language created by Dennis Ritchie at Bell Labs in 1972 to develop the UNIX operating system. It quickly became popular due to its efficiency, flexibility, and portability. In 1989, ANSI standardized C to promote consistency, and it has since become one of the most widely used programming languages. Variables in C must be declared before use and can be numeric like integers and floats, or character strings. Variable names follow specific rules and types must be specified in declarations.
C programming Training in Ambala ! Batra Computer Centrejatin batra
Batra Computer Centre is An ISO certified 9001:2008 training Centre in Ambala.
We Provide C Programming Training in Ambala. BATRA COMPUTER CENTRE provides best training in C, C++, S.E.O, Web Designing, Web Development and So many other courses are available.
C is a general purpose programming language developed in the 1970s. It has features like control structures, looping statements, and arrays that make it well-suited for business and scientific applications. A C program executes in four steps - creating the program, compiling it, linking it to libraries, and executing the final executable file. C has keywords, variables, data types, operators, and conditional statements that allow for structured programming and control flow.
The document provides an overview of the C programming language. It discusses that C was developed at Bell Labs in the 1970s and influenced by other languages like BCPL. The core concepts covered include C's character set, keywords, basic program structure with main function, header files, data types, variables, constants, and declarations. An example "Hello World" C program is also given.
Here are the values of c in each case:
1. int a = 10, b = 2;
c = 12, 8, 20, 5
2. float a = 10, b = 2;
c = 12, 8, 20, 5
3. int a = 10; float b = 2;
c = 12, 8, 20, 5
The data types of the operands determine the result. For integer operands, the result is an integer. For floating point operands, the result is floating point.
C is a general-purpose programming language developed at Bell Labs in the 1970s. It discusses the basics of C programming, including its history, structure, keywords, variables, data types, and provides an example "Hello World" program. The document provides an overview of the key elements of C for a beginner programmer to understand how to get started with C.
The document provides an overview of the C programming language. It discusses that C was developed at Bell Labs in the 1970s and is a general purpose language closely associated with UNIX. It then covers C's character set, keywords, basic program structure including header files and library functions, data types, variables, constants, and provides a simple "Hello World" example program.
This document provides an overview of C programming, including getting started, keywords, identifiers, variables, constants, and data types. It explains that C is an efficient programming language widely used for system and application software. It also covers the basics of compilers, keywords, variables, constants, and different data types like integers, floats, characters, and more. The document is intended for beginners to provide a solid foundation of C programming concepts.
The document discusses the C programming language. It begins by providing an overview of the history and development of C, originating from earlier languages like ALGOL and BCPL. It then covers basic C concepts like data types, variables, constants, and user-defined types. Examples are given to declare and assign values to variables of different types. The document also discusses defining symbolic constants and reading input from the keyboard. Finally, it introduces the topic of operators and expressions in C.
C was originally developed in the 1970s by Dennis Ritchie at Bell Labs. It is a high-level, general-purpose programming language that allows for both system and applications programming. C contains features that bridge machine language and high-level languages, making it useful for system programming. The basic elements of C include keywords, variables, constants, operators, and other tokens that are constructed from characters, numbers, and symbols.
The document provides information on the C programming language, including its history, structure, and key concepts. It discusses how C was developed at Bell Labs in the 1970s and influenced by other languages. It also describes the basic structure of C programs, which typically include header files, main functions, and statements organized into functions. The document also covers important C concepts like data types, variables, constants, and tokens.
C was originally developed in the 1970s by Dennis Ritchie at Bell Labs. It is a high-level, general-purpose programming language that allows for both system and applications programming. C contains features that bridge machine language and high-level languages, making it useful for both system and applications programming.
The document discusses various topics related to programming style in C language including tokens, keywords, variables, constants, data types, operators, and flow control statements. It provides definitions and examples of each. Specifically, it defines the different types of tokens in C and gives an example program to demonstrate tokens. It also lists and describes the 32 keywords in C and provides rules for constructing identifiers and variables. Further, it discusses various data types in C including integer, floating-point, and character types and provides their storage sizes and value ranges. The document also covers the different categories of operators in C like arithmetic, relational, logical, bitwise, and assignment operators including their syntax and examples. Finally, it discusses selection and repetition statements like
This document provides an introduction and overview of the C programming language. It discusses the history and development of C, why C is still widely used today despite newer languages, and shows a simple "Hello World" example as a first C program. The document also covers basic C programming concepts like data types, variables, constants, and input/output functions. It provides examples of declaring variables, assigning values, and using the printf statement to output values.
The document provides an introduction to the C++ programming language, including its history, characteristics, and components. It notes that C++ was created in the 1980s by Bjarne Stroustrup at Bell Labs as an enhancement to the C language that added object-oriented programming capabilities while still maintaining efficiency. Some key characteristics of C++ include object-oriented programming, portability, modular programming, C compatibility, and a wide range of library functions. The document discusses the basic building blocks of C++, including tokens like identifiers, keywords, constants, punctuators, and operators.
This document provides an overview of programming in C. It discusses the importance of C as the base language for other programming languages and its efficiency. The basic structure of a C program is outlined as having documentation, include, define, global declaration, and main sections. Interpreters and compilers are explained as the two methods for running C programs, with compilers producing faster executable programs. Key aspects of C as a language are covered such as variables, data types, and constants.
This document provides an overview of the C programming language. It discusses that C was developed in the 1970s as a system programming language and is still widely used today. The document outlines key features of C including data types, operators, expressions, input/output functions, and the basic structure of a C program with function definitions and variable declarations. It also describes basic program elements in C like variables, constants, and data types in detail.
C was originally developed in the 1970s by Dennis Ritchie. It is a high-level, general-purpose programming language that contains features allowing it to be used for both system and application programming. The document discusses the character set, tokens, variables, constants, and operators in C programming. Key topics include identifiers, keywords, data types for variables, integer/floating point/character/string constants, and arithmetic, assignment, relational, and logical operators.
C was originally developed in the 1970s by Dennis Ritchie at Bell Labs. It is a high-level, general-purpose programming language that contains features allowing it to be used for both system and application programming. The C language consists of characters, numbers, and symbols that form tokens like identifiers, keywords, constants, operators, and punctuation. Variables, functions, and other elements in C are given unique identifiers to represent storage areas that can be manipulated. Constants are values that cannot be altered, and different types of constants like integers, floats, characters, and strings are used. Operators perform operations on values and variables, and different classes of operators exist for arithmetic, assignment, comparison, logic, and other purposes.
The document discusses data types in C programming. It covers the basic data types like int, float, char, etc. It also discusses variables, constants, keywords, operators and functions in C. The document provides examples of integer, real and character constants. It explains variable naming rules and different data types supported in C like char, short, int, float, double etc along with their sizes and ranges. It also provides a simple "Hello World" example C program.
1. Er. Sachin Verma
B.Tech/Anand Engineering College Agra
Electrical & Electronics Department
Web Address:
For more detail CLICK HERE OR Mail to:way2sachinverma@gmail.com
18/01/2012
A Brief History of the C Language
Before we start any complex program in C, we must understand what really C is, how it came into
existence and how it differs from other languages of that time.
C is a programming language which born at “AT & T’s Bell Laboratories” of USA in 1972. It was written
by Dennis Ritchie. This language was created for a specific purpose: to design the UNIX operating
system (which is used on many computers). From the beginning, C was intended to be useful--to allow
busy programmers to get things done. Because C is such a powerful, dominant and supple language, its
use quickly spread beyond Bell Labs. In the late 70’s C began to replace widespread well-known
languages of that time like PL/I, ALGOL etc. Programmers everywhere began using it to write all sorts of
programs. Soon, however, different organizations began applying their own versions of C with a subtle
difference. This posed a serious problem for system developers. To solve this problem, the American
National Standards Institute (ANSI) formed a committee in 1983 to establish a standard definition of C.
This committee approved a version of C in 1989 which is known as ANSI C. With few exceptions, every
modern C compiler has the ability to adhere to this standard. ANSI C was then approved by the
International Standards Organization (ISO) in 1990.
Now, what about the name? Why it was named C, why not something else. The C language is so named
because its predecessor was called B. The B language was developed by Ken Thompson of Bell Labs.
1
2. Why Use C?
In today's world of computer programming, there are many high-level languages to choose from, such
as Pascal, BASIC, and Java. But C stands apart from all these languages. This is due to its many desirable
qualities. It is a robust language whose rich set of built-in functions and operators can be used to write
any complex logic program. The C language compiler combines the capabilities of a low level language
with the features of a high level language. Therefore the language is suitable for writing both system
software as well as business packages & other software.
Program written in c are very efficient and fast. This is due to its variety of data types and
powerful operators. It is many time faster than BASIC. This helps developers in saving their
valuable time.
C is a powerful and flexible language which helps system developers to deliver various complex
tasks with ease. C is used for diverse projects as operating systems, word processors, graphics,
spreadsheets, and even compilers for other languages.
C is popular among professional programmers for programming, as a result, a wide variety of C
compilers and helpful accessories are available.
C is highly portable language. This means that a C program written for one computer system (an
IBM PC, for example) can be run on another system (a DEC VAX system, perhaps) with little or
no modification. Portability is enhanced by the ANSI standard for C, the set of rules for C
compilers.
C’s another striking feature is its ability to extend itself. A C program is basically a collection of
various function supported by C library (also known as header files). We can also add our own
functions to the C library. These functions can be reused in other applications or programs by
passing pieces of information to the functions, you can create useful, reusable code.
Writing C program with user-defined functions makes program more simple and easy to
understand. Breaking a problem in terms of functions makes program debugging, maintenance
and testing easier.
As these features shows that C is an excellent choice for your first programming language.
The C Character Set
A character denotes any alphabet, digit or symbols to represent information. The following are the
valid alphabets, numbers and special symbols permitted in C
Numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Alphabets: a, b,….z A, B,……………..Z
Arithmetic Operations: +, -, *, /, %(Mod)
2
3. Special Characters:
CONSTANTS, VARIABLES AND KEYWORDS
A’ constant’ is an entity that does not change, but a ‘variable’ as the name suggests may change. We do
a number of calculations in a computer and the computed values are stored in some memory spaces. In
order to retrieve and re-use those values from the computer’s memory locations they are given names.
Since the value stored in each location may change, the names given to these locations are called as
‘variable names’.
1. Constants
There are mainly three types of constants namely: integer, real and character constants.
Integer Constants:
The integer constants are:
Whole Numbers
E.g. 25, 35, -25, -46
Computer allocates only 2 bytes in memory.
16th bit is sign bit. (If 0 then +ve value, if 1 then –ve value)
3
4. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
214 213 212 211 210 29 28 27 26 25 24 23 22 21 20
=1*1 + 4*1 + 8*1 + 16*1 + 32*1 + 64*1 + 128*1 + 256*1 + 512*1 + 1024*1 +
2048*1 + 4096*1 + 2*1 + 8192*1 + 16284*1
= 32767 (32767 Bits can be stored for integer constants)
32768 is negative
-32767 is minimum
Decimal integer constant:
0 to 9
.g.: 49, 58, -62 … (40000 cannot come bcoz it is > 32767)
Octal integer constant:
0 to 7
Add “0” before the value.
E.g.: 045, 056, 067
Hexadecimal constant:
0 to 9 and A to F
Add 0x before the value
E.g.: 0x42, 0x56, 0x67
2. Real constant:
The real or floating point constants are in two forms namely fractional form and the
exponential form.
A real constant in fractional form must:
Have at least one digit.
It must have a decimal point.
Could have positive or negative sign (default sign is positive).
Must not have commas or spaces within it.
Allots 4 bytes in memory.
Ex: +867.9, -26.9876, 654.0
In exponential form, the real constant is represented as two parts. The part lying before
the ‘e’ is the
‘mantissa’, and the one following ‘e’ is the ‘exponent’.
4
5. The real constant in exponential form must follow the following rules:
The mantissa part and the exponential part should be separated by the letter
‘e’.
The mantissa may have a positive or negative sign (default sign is positive).
The exponent must have at least one digit.
The exponent must be a positive or negative integer (default sign is positive)
The range of real constants in exponential form is 3.4 e-38 to 3.4 e+38.
Ex: +3.2e-4, 4.1e8, -0.2e+4, -3.2e-4
3. Character constant:
A character constant is an alphabet, a single digit or a single special symbol enclosed
within inverted commas. The maximum length of a character constant can be 1
character.
Allots 1 byte of memory.
Ex: ’B’, ’l’, ’#’
Types of C Variables
Variable names are names given to locations in the memory. These locations can contain
integer, real or character constants. An integer variable can hold only an integer constant, a real
variable can hold only a real constant and a character variable can hold only a character
constant.
Types of C Variables:
Rules for Constructing Variable Name
A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers
allow variable names whose length could be up to 247 characters.
• The first character in the variable name must be an alphabet.
• No commas or blanks are allowed within a variable name.
• No special symbol other than an underscore (as in net_sal) can be used in a variable
name.
Ex.: si_int
e_hra
pod_e_81
C compiler makes it compulsory for the user to declare the type of any variable name that he
wishes to use in a program. This type declaration is done at the beginning of the program.
Following are the examples of type declaration statements:
Ex.: int si, e_hra ;
float bas_sal ;
char code ;
5
6. Since, the maximum allowable length of a variable name is 31 characters; an enormous number
of variable names can be constructed using the above-mentioned rules. It is a good practice to
exploit this enormous choice in naming variables by using meaningful variable names.
Some Useful Tips:
Declaring Variables in C
Variables are what make your programs zoom. Programming just can't get done without them.
E.g. Valerie Variable is a numeric variable. She loves to hold numbers — any number; it doesn't
matter. Whenever she sees an equal sign, she takes to a value and holds it tight. But if there is
another equal sign, and she takes on a new value. In that way, Valerie is a little flaky. You could
say that Valerie's values vary, which is why she's a variable.
Now suppose Victor Variable is a string variable. He contains bits of text — everything from one
character to several of them in a row. As long as it's a character, Victor doesn't mind. But which
character? Victor doesn't care — because he's a variable, he can hold anything.
Yes, there is a point here. There are two main types of variables in C: numeric variables
that hold only numbers or values, and string variables that hold text, from one to
several characters long.
There are several different types of numeric variables, depending on the size and
precision of the number.
Before you use a variable, it must be declared.
This is — oh, just read the next section.
"Why must I declare a variable?"
You are required to announce your variables to the C compiler before you use them. You do
this by providing a list of variables near the beginning of the program. That way, the compiler
knows what the variables are called and what type of variables they are (what values they can
contain). Officially, this process is known as declaring your variables.
For example:
int count;
char key;
Two variables are declared here: an integer variable, count; a character variable, key; Doing this
at the beginning of the program tells the compiler several things.
First, it says, "These things are variables!"
Second, the declarations tell the compiler which type of variable is being used. The compiler
knows that integer values fit into the count variable.
Third, the compiler knows how much storage space to set aside for the variables. This can't be
done "on the fly" as the program runs. The space must be set aside as the compiler creates the
program.
Declare your variables near the beginning of your program.
6
7. Obviously, you won't know all the variables a program requires before you write
it. So, if you need a new variable, use your editor to declare it in the program.
If you don't declare a variable, your program does not compile. The proper
authorities issue a suitable complaint message.
Most C programmers put a blank line between the variable declarations and the
rest of the program.
C Keywords:
C makes use of only 32 keywords or reserved words which combine with the formal syntax to
form the C programming language. Note that all keywords in C are written in lower case. A
keyword may not be used as a variable name.
Identifiers:
Identifiers are names of variables, functions, and arrays. They are user-defined names,
consisting of sequence of letters and digits, with the letters as the first character. Lower case
letters are preferred. However, the upper case letters are also permitted. The (_) under score
symbol can be used as an identifier.
7
8. Examples: 1. #define N 10 2. # define a 15
Here 'N' and 'a' are user-defined identifiers They consist of a combination of characters and
digits. You can then use letters, digits, or underscores for all subsequent characters. Letters
include all uppercase characters, A through Z, and all lowercase characters, a through z. Digits
include the characters 0 through 9.
Reserved Words:
Reserved words are identifiers that you might not use as names for variables, functions,
objects, or methods. This includes keywords along with identifiers that are set aside for possible
future use.
Data types:
All C compilers support a variety of data types. This enables the programmer to select the
appropriate data type as per the need of the application. Which type of data is storing in a
variable is known as data type. Generally data is represented using numbers or characters. The
numbers may be integers or real.
A C language programmer has to tell the system before-hand, the type of numbers or
characters he is using in his program. These are data types. There are many data types in C
language. A C programmer has to use appropriate data type as per his requirement.
C language data types can be broadly classified as
* Primary data type
* Derived data type
* User-defined data type
All C Compilers accept the following fundamental data types
Integer -------------------------------------> int
Character ----------------------------------> char
Floating Point ------------------------------> float
Double precision floating point------------> double
Void ---------------------------------------> void
The size and range of each data type is given in the below
char -----------------------------------> -128 to 127
8
9. int -----------------------------------> -32768 to +32767
float ---------------------------------->3.4 e-38 to 3.4 e+38
double --------------------------------> 1.7 e-308 to 1.7 e+308
Integer Type:
Integers are whole numbers with a machine dependent range of values. A good programming
language as to support the programmer by giving a control on a range of numbers and storage
space. C has 3 classes of integer storage namely short int, int and long int. All of these data
types have signed and unsigned forms. A short int requires half the space than normal integer
values. Unsigned numbers are always positive and consume all the bits for the magnitude of
the number. The long and unsigned integers are used to declare a longer range of values.
Floating Point Types:
Floating point number represents a real number with 6 digits precision. Floating point numbers
are denoted by the keyword float. When the accuracy of the floating point number is
insufficient, we can use the double to define the number. The double is same as float but with
longer precision. To extend the precision further we can use long double which consumes 80
bits of memory spaces.
Void type:
Using void data type, we can specify the type of a function. It is a good practice to avoid
functions that does not return any values to the calling function.
Character Type:
A single character can be defined as a defined character type of data. Characters are usually
stored in 8 bits of internal storage. The qualifier signed or unsigned can be explicitly applied to
char. While unsigned characters have values between 0 and 255, signed characters have values
from –128 to 127.
9
10. Data types and their control strings
In addition, there are a number of qualifiers that can be applied to these basic types. Short and
long apply to integers:
short int sh;
long int counter;
The word int can be omitted in such declarations, and typically it is. The intent is that short and
long should provide different lengths of integers where practical; int will normally be the
natural size for a particular machine. short is often 16 bits long, and int either 16 or 32 bits.
Each compiler is free to choose appropriate sizes for its own hardware, subject only to the the
restriction that shorts and ints are at least 16 bits, longs are at least 32 bits, and short is no
longer than int, which is no longer than long.
10
11. The qualifier signed or unsigned may be applied to char or any integer. unsigned numbers are
always positive or zero, and obey the laws of arithmetic modulo 2n, where n is the number of
bits in the type.
So, for instance, if chars are 8 bits, unsigned char variables have values between 0 and 255,
while signed chars have values between -128 and 127 (in a two's complement machine.)
Whether plain chars are signed or unsigned is machine-dependent, but printable characters are
always positive.
The type long double specifies extended-precision floating point. As with integers, the sizes of
floating point objects are implementation-defined; float, double and long double could
represent one, two or three distinct sizes.
11