Posts

Showing posts from August, 2020

C - Conditional Statement

 Control Statement: Generally C program statement is executed in a order in which they appear in the program. But sometimes we use decision making condition for execution only a part of program, that is called control statement. Control statement defined how the control is transferred from one part to the other part of the program. There are several control statement like if...else, switch, while, do....while, for loop, break, continue, goto etc. if statement:  Statement execute set of command like when condition is true and its syntax is   If (condition)   Statement;  The statement is executed only when condition is true. If the if statement body is consists of several statement then better to use pair of curly braces. Here in case condition is false then compiler skip the line within the if block.  void main()  {   int n;   printf (“ enter a number:”);   scanf(“%d”,&n); If (n>10)   Printf...

C - Operator

 Operators: This is a symbol use to perform some operation on variables, operands or with the constant. Some operator required 2 operand to perform operation or Some required single operation.  Several operators are there those are, arithmetic operator, assignment, increment , decrement, logical, conditional, comma, size of , bitwise and others.   1. Arithmatic Operator: This operator used for numeric calculation. These are of either Unary arithmetic operator, Binary arithmetic operator. Where Unary arithmetic operator required only one operand such as +,-, ++, --,!, tiled. And these operators are addition, subtraction, multiplication, division. Binary arithmetic operator on other hand required two operand and its operators are +(addition), -(subtraction), *(multiplication), /(division), %(modulus). But modulus cannot applied with floating point operand as well as there are no exponent operator in c. Unary (+) and Unary (-) is different from addition and subtrac...

C - Constants and Variables

Image
 Constants And Variable Constants: Constant is a any value that cannot be changed during program execution. In C, any number, single character, or character string is known as a constant. A constant is an entity that doesn’t change whereas a variable is an entity that may change. For example, the number 50 represents a constant integer value. The character string "Programming in C is fun." is an example of a constant character string. C constants can be divided into two major categories:  Primary Constants  Secondary Constants  These constants are further categorized as    Numeric constant   Character constant   String constant Numeric constant:   Numeric constant consists of digits. It required minimum size of 2 bytes and max 4 bytes. It may be positive or negative but by default sign is always positive. No comma or space is allowed within the numeric constant and it must have at least 1 digit. The allowable range for integer const...

C - character set, identifiers, keywords

Image
 character set, identifiers, keywords  Character set:  A character denotes any alphabet, digit or special symbol used to represent information. Valid alphabets, numbers and special symbols allowed in C are The alphabets, numbers and special symbols when properly combined form constants, variables and keywords. Identifiers:   Identifiers are user defined word used to name of entities like variables, arrays, functions, structures etc. Rules for naming identifiers are:  1) name should only consists of alphabets (both upper and lower case), digits and underscore (_) sign. 2) first characters should be alphabet or underscore  3) name should not be a keyword  4) since C is a case sensitive, the upper case and lower case considered differently, for example code, Code, CODE etc. are different identifiers.    5) identifiers are generally given in some meaningful name such as value, net_salary, age, data etc. An identifier name may be long, s...

C - Compiling and executing the Programs

 Steps for Compiling and executing the Programs A compiler is a software program that analyzes a program developed in a particular computer language and then translates it into a form that is suitable for executionon a particular computer system. Figure below shows the steps that are involved in entering, compiling, and executing a computer program developed in the C programming language and the typical Unix commands that would be entered from the command line. Step 1:  The program that is to be compiled is first typed into a file on the computer system. There are various conventions that are used for naming files, typically be any name provided the last two characters are “.c” or file with extension .c. So, the file name prog1.c might be a valid filename for a C program. A text editor is usually used to enter the C program into a file. For example, vi is a popular text editor used on Unix systems. The program that is entered into the file is known as the source program becaus...

Structure of C program

Structure of c program:   1 ) Comment line  2) Preprocessor directive  3 ) Global variable declaration  4) main function( ) { Local variables; Statements; } User defined function } } Comment line It indicates the purpose of the program. It is represented as /*……………………………..*/ Comment line is used for increasing the readability of the program. It is useful in explaining the program and generally used for documentation. It is enclosed within the decimeters. Comment line can be single or multiple line but should not be nested. It can be anywhere in the program except inside string constant & character constant. Preprocessor Directive: #include tells the compiler to include information about the standard input/output library. It is also used in symbolic constant such as #define PI 3.14(value). The stdio.h (standard input output header file) contains definition &declaration of system defined function such as printf( ), scanf( ), pow( ) etc. General...

C Introduction

Image
 Introduction to C   C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. In the late seventies C began to replace the more familiar languages of that time like PL/I, ALGOL, etc ANSI C standard emerged in the early 1980s, this book was split into two titles: The original was still called Programming in C, and the title that covered ANSI C was called Programming in ANSI C. This was done because it took several years for the compiler vendors to release their ANSI C compilers and for them to become ubiquitous.  It was initially designed for programming UNIX operating system. Now the software tool as well as the C compiler is written in C. Major parts of popular operating systems like Windows, UNIX, Linux is still written in C. This is because even today when it comes to performance (speed of execution) nothing beats C. Moreover, if one is to extend the operating system to work...