Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Programming in C

Programming in C

Ratings: (0)|Views: 247|Likes:
Published by inpreetk

More info:

Published by: inpreetk on Dec 01, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





Programming in C
History of C Programming Language
C language is the middle – level programming language. The C language was developed at AT&T BellLaboratories, USA by Denis Ritchie in 1972. This is general-purpose language.Before the development of C language there were many languages that were developed, but theselanguages served some specific purpose. For example, for commercial applications, where lot of data areneeded to be stored and retrieved, COBOL is used; for Engineering and Scientific applications, whichneeds more calculating power than data storage and retrieval facilities, FORTRAN is used, etc. There wasa need for a common language for all these purposes. “C” came into existence, after the development of many languages like ALGOL 60, CPL, BCPL, B, and many others, which didn’t actually serve the purposeand were a specific purpose language.C as a programming language is sometimes referred to as a middle-level language. This is because it provides much flexibility and ease for the programmer as provided by any high-level language and thesame time it provides and supports certain features and concepts that are necessary for good system (low-level) programming.
Explain the use of the following:printf Function
 – The printf function is used to print out a message either on screen or paper. The syntaxof printf function is as follows: printf(“text to be printed”);When printf is used, it means that printing function is to be called for action. The statement or texts used inquotes are called the control strings.
newline Character \n
– The newline symbol instructs the computer to advance to the next new line before printing subsequent information. The printf function does not do this automatically.
Semicolon ;
- The end of any statement in C Programming is denoted by a semicolon. In C, all statementsare terminated with a semicolon.
– Braces are used at the start as well as at the end of the program. The open brace { is used to begina program, just below main() function. The alignment of the braces on either side is not strictlynecessary but it makes the program more readable. The closed brace } is used to denoted end of a program.
– The comment demonstrates the method used in C to add a comment or remark to a program.This is done by beginning the comment with the two characters /* and ending it with the characters*/. No space can be included between the two characters. Between these pairs of characters(delimiters), any characters may be included either in upper or lowercase. In other words, acomment appears as follows:/* Whatever you want using any characters at all */The only restriction is that a comment nay not contain the closing delimiter */ as a part of the comment’stext. All such comments are ignored by the compiler ad have no effect on the way the program runs. Theyincluded because they serve as an excellent way of internally documenting the programs. When a programis printed out, those comments appear along with the instructions. Comments may start on the same line asanother statement or on a line of its own. It may also extend over any number of lines if the terminatingdelimiter is placed at the appropriate point.
What are Constants? Give types and rules for each one of them.
Constant is a quantity that doesn’t change and can be stored at any location in the memory of the computer.These quantities may be combinations of alphabets, numbers or special symbols in C.eg: 2y=30, where 2 and 30 are constants i.e., their value cannot be changed.C Constants can be divided into two categories:1.Primary constants1
2.Secondary constantsPrimary constants are as follows:i.Integer Constants – An integer constant refers only to numbers. It may be a single digit or combinationof digits. Generally, integer constants are written in decimal number system, which consist of combination of digits from 0-9.Rules for constructing Integer constants.a)An integer constant must contain of at least one digit.b)It should not contain decimal values.c)The numbers could either be positive or negative.d)It does not allow commas or blank space.e)The range of integer constant is –32768 to +32767ii.Float Constants A float constant refers to numbers that contains a decimal point or an exponent or  both. The float constants are often known as real constants that could be written in two forms: fractionalor exponential.Rules for constructing Float constantsa)A float constant must consist of at least one digit. b)It should have decimal valuesc)The numbers could either be positive or negatived)It does not allow commas or blank spacese)A letter ‘e’ should separate the mantissa part and the exponent part. For example, 301224x10
would be represented as 301224 e –17 in float constants.f)The range of real constants is much greater than integer constants, which is expressed as –3.4e38 to3.4e38.iii.Character Constants – A character constant is defined as a single alphabet, a single digit or a specialsymbol enclosed within single quotes (‘r’).Rules for constructing Character constantsa)The maximum length of character constant can be 1 character. b)The quotes within the character is enclosed must point to the left as ‘a’.c)The characters constant have integer values determined by computer’s ASCII character set.d)The range of character constant is –128 to +127.Secondary Constants are as follows:i.Logical Constants – A logical constant refers to either of two values zero or non-zero. Zero is treatedas
whereas non-zero value is treated as
eg: 12, -24, 1.7, are logical constants with true valuewhereas 0 is a logical constant with false value. These constants help solving logical expression andcomplex conditions easily.ii.String Constant A string constant is a combination of characters enclosed within double quotes(“India”). Some special characters like backslash are included as a part of string constant. Each of thestring constant is ended with special character called null character represented as ‘\0’ that acts as astring terminator but it is not displayed on the screen.iii.Pointer Constants – These include the name of an array without subscripts and the name of a functionwithout parentheses. A string literal actually is an instance of a constant pointer, since its value is a pointer to the string.
What are Variables? Explain
Variables are quantities that can be changed. Variable names are the names given to the locations inmemory of a computer where different values are stored. The locations may however contain an integer,character, real or any constant but if a variable has been declared with int
data type, it must be contain aninteger value and so on. While declaring a variable the first character in the variable name must be an2
alphabet. The name of the variable should not have any commas, blank spaces or special symbols exceptthe underscore (_). We cannot give name of the variable similar to any reserved word of the C programming language.Examples of declarations:int i;char var;float floating-point;int year, month;While declaring the variables you can also assign some initial values to them as shown below:int i = 10;char c = ‘A’;int j = i;Rules for naming variables:1)Variables names must begin with a letter of the alphabet. In C, the underscore character is considered aletter. It is legal to start a variable name with the underscore character, but this practice is discouragedto prevent possible conflict with some special system names that begin with the underscore.2)The first character may be followed by a sequence of letters and/or digits (0 through 9).3)On most microcomputers, the first seven or eight characters (depending upon the version upon theversion of C) of the name must be unique. That is, no other variable used in the program may beginwith the same seven or eight characters. If it does, it will be treated as the same name and the programmay produce questionable result.4)The compiler regards uppercase and lowercase letters as different, although both may be used inconstructing variable names. Therefore, the variable names NET, net and Net are regarded as differentvariable names in C. Usually, variable names are entirely entered in lowercase.5)No variable name may be a keyboard. This rule means we cannot give a variable a reserved name suchas int.6)No special characters, such as a blank space, period, semicolon, commas or slash are permitted invariable names.
What are operators? Classify them.
Operators refer to symbol that represents a particular operations to be performed on data. The data, onwhich the operation is to be performed, is called operand and the term, which performs the function, scalled the operator.For example, in the expression, 12 + 24, 12 and 24 are operands whereas + is an operator. An operator needs two or one operand to perform any action.1)Assignment Operator – Assignment operator is used to assign the value to a variable. This is done bythe assignment operator ‘=’. The syntax of assignment operator is identifier = expression, whereidentifier generally represents a variable and expression represents a constant, a variable or a morecomplex expression. For example, a=30; /* here variable ‘a’ is given a value from constant 30 */2)Arithmetic Operators – Arithmetic operators are used in mathematical expressions. There are basicallyfour arithmetic operators in C. They are(a)+ (Addition) This operator is used to add two numbers. Eg: i=3+j;(b)(Subtraction) This operator is used to subtract two numbers. Eg: i=3-j;(c)* (Multiplication) This operator is used to multiply two numbers. Eg: i = j*k;(d)/ (Division) This operator is used to divide two numbers. Eg: i = j/2;3)Modulus Operator – This operator can also be considered a part of arithmetic operator because this isalso used for mathematical operations. This is generally represented as ‘%’. This operator returnsremainder after integer division and is a supplement to the division operator as the division operator returns the quotient. It can only be applied to integer data type. For example, 24 % 7, will give theoutput 3 as it is the remainder. If the numerator is smaller than the denominator, then the operator willreturn the numerator itself. Eg: j = 2 % 4; /* this will store value 2 in j */4)Relational Operators – These operators are used to compare to check whether they are equal, unequal,greater or lesser than the other. The operands can be variables, constants or expressions that ultimately3

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->