




























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Benefits of all c programming students.
Typology: Lecture notes
1 / 36
This page cannot be seen from the preview
Don't miss anything!
Back to notes section : What is Complier? Compiler is a program that converts the source code (program written in a language other than machine language ) in to machine code. Computer can understand machine code and execute machine code. Therefore we can state that compiling is a process of converting source code to machine code if source code is error free. What is the basic structure of c program? Consider a simple program #include <stdio.h> #include <conio.h> void main() { int a,b; printf(“\n enter two values”); scanf(“%d %d”,&a,&b); c=a+b; printf(“\n addition=%d”,c); getch(); } We can note following facts:
source file (program written in high level language). Some preprocessor are: #include, #define, #ifdef, #ifndef, #undef, #else, #endif, #pragma etc. What are the popular features of ‘C’ language? The features are:
programming language was developed with reduced feature of Alogol-60 but it was still vague and did not become popular. Later on basic combined programming language was developed with reduced feature when compared to combined programming language. Basic Combined Programming Language had very limited feature and did not become popular. B language was developed by Ken Thompson as further enhancement to Basic Combined Programming Language. Dennis Ritchie developed some new feature and used features of language ‘B’ and Basic Combined Programming Language and developed ‘c’ and ‘c’ became popular. Why c is called a middle level language? All the programming languages can be divided into two categories: (a) Problem oriented languages or high level languages: These language have been designed to give a better programming efficiency. i.e. faster program development E.g. Fortran, Basic. (b) machine oriented languages or low level languages: These language have been designed to give a better machine efficiency means faster program execution. ‘c’ stands in between these two categories. That is why it is called a middle level language it has got relatively good programming efficiency (as compared to machine oriented languages) and relatively good machine efficiency (as compared to high level languages). What do you mean by character set of C? A character denotes any alphabet, digit or special symbol used to represent information. All those characters which can be part of a ‘c’ program and program still remains valid is knowns as ‘c’ character set. Few e.g. as alphabets a-z, digits -9, special symbols ,,{,} etc. What is Syntax? Syntax is correct way of writing statement according to rules suggested by language. What is constant?/What are the several type of constant that c language supports?. what is the difference between variable and constant? how can variable be initialized? A constant is a quantity that doesn’t change during program run time. This quantity can be stored at a location in memory. A variable is that whose value can change during run time of program.
‘y’ invalid is ‘ab’ /* only single character can be used / invalid is “a” / single quote must be used */ (B) Secondary constants Array, pointers, structure, union, enum etc. are known as secondary constant. What are the different data types available in c? ans: char,unsingned char, int,unsigned int,long ,unsigned long,float,double, long double. What is variable? Variable is name given to a location of computer memory where we can store value and retrieve the stored value by variable name. Value of variable can change during program run time and it is fundament requirement of any programming language. Rules for constructing identifier (variable/pointer/function name):
What is keyword? Keyword or reserved word is word whose meaning is well defined for compiler we can use it in our program but we can not alter its meaning. e.g. int, float, do, while etc. There are such 32 keywords. What is statement or instruction? An instruction requests computer to perform some work. These are following types:
(a)Values of variable or constant can be read by: scanf function whose syntax is scanf(“format strings”,&var1,&var2…); format string can be constructed using format specifier character e.g. %c, %d, %u, %f. Which format specifier to use? depends on data type of variable to read value in. Suppose variables are declared as int a,b; float e; char c; then we need statement scanf(“%d %d %f %c”,&a,&b,&e,&c); Since a and b are int types we used corresponding format specifier %d two times because there are two int type variables to read values in. Since f and c are float and char types respectively we used corresponding format specifier %f and %c. It means that no. of variables required read values in, must match with no. of format specifier. Each data type uses a predefined format specifier and we have to use the predefined one. (b) writing of values of variable or constant: it can be done using printf statement whose syntax is as follows printf(“message to print”); e.g. printf(“enter an integer”); or printf(“format string”,var1,var2); if we have declared variables as: int a=10; float b=20; we can give statement printf(“%d %f”,a,b); Since a is int we used %d format specifier. Since b is float we used %f format specifier The values of variable or constant to print replace format specifier at print time.
Therefore output will be 10 20. if we give statement printf(“a=%d,b=%f”,a,b); output will be a=10 b=20. How can we read character constant in character variable? (Single character input-output) Character variable is treated internally as integer therefore we have two ways to read a character constant in character variable. (1)Character constant can be read using %c format specifier when to read a single character. Consider following program: #include<stdio.h> #include<conio.h> void main() { char p; printf(“\n enter a character”); scanf(“%c”,&p); /* or we can use c=getchar(); c=getche(); c=getch(); */ printf(“\n the character read is %c and ascii value is %d”,p,p); getch(); } If we enter a character ‘a’ during run time of program then output will be: The character read is a and ascii value is 97 (2)Character constant can be read using %d format specifier when to read an integer value corresponding to ascii value of character to read #include<stdio.h> #include
could also be written as:- signed int i; qualifier can be two types: a)Size qualifier size qualifier modifies the range of value, a variable can store. short: applies to int long: applies to int and double b)Sign qualifier signed: applies to int, char unsigned: applies to int, char What do you mean by typedef statement?/define type declaration in c. The typedef (keyword) statement allows creating new name for existing data type. For example if we write a statement typedef unsigned long ulong; Then we can use statement :- ulong a; This means that: unsigned long u; What is the difference between ‘a’ and “a”? ‘a’ “a” ‘a’ is a character constant. “a” is a string constant Character constant can have a single character enclosed inside single quote. String constant can have one or more character enclosed inside double quotes. a character constant takes just one byte of memory. a string constant takes no. memory that is sum of no. of characters inside double quotes plus 1 byte taken by null character. %c is format specifier for formatted%s is format specifier for formatted
input/output. input/output. getch(),getchar(),getche() are unformatted input library functions. gets() is a unformatted input library function. What are the different types of operators available in c? Different types of operator are available in ‘C’ are: Arithmetic operators +,-,,/,% Relational operators >,<,>=,<=,= = ,!= Logical operators &&,||,! Assignment operators = compound assignment operators are: +=,-=,%=,/= etc. Increment/decrement operators ++,-- Conditional operators ( condition ) ?true statement :false statement Bitwise operators &,|,^,<<,>>,~ Comma operators , Other operators Sizeof Write short notes on shorthand operators. short hand operator are ++,- -,+=,-=,= etc. suppose int a=1; a++; value of a is now 2
<< left shift operator
right shift operator ~ complement operator suppose int a=13 ,b=7,c; c=a&b; first row is a’s bit pattern ,second row is b’s bit pattern ,third row is c’s bit pattern 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 c=a|b; first row is a’s bit pattern ,second row is b’s bit pattern ,third row is c’s bit pattern 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 c=a^b; first row is a’s bit pattern ,second row is b’s bit pattern ,third row is c’s bit pattern 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 c=a<<3; first row is a’s bit pattern ,second row is c’s bit pattern 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 clearly c= a*(2^3 ) c=a>>3; first row is a’s bit pattern ,second row is c’s bit pattern 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1
clearly c= a/(2^3 ) c=~a; first row is a’s bit pattern ,second row is c’s bit pattern 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 Explain the behavior of right shift operator for positive and negative integer. Zeros are always inserted in the left if integer is positive otherwise 1 is inserted in the left, if integer is negative when using right shift operator. if we assign -3 to a variable ‘a’ int a=-3; then binary representation of ‘a’ in two’s complementary system is computed as follows: binary representation of positive 3 is 0000 0000 0000 0011 taking complementary 1111 1111 1111 1100 by adding 1 to get two’s complementary 1111 1111 1111 1101 which is binary pattern of - now c=a>>2; will shift the value of a by 2 bit positions to the right and will insert two 1’s in the left. so value of c will be 1111 1111 1111 1111 once again taking complementary 0000 0000 0000 0000 adding 1 to get two’s complementary 0000 0000 0000 0001 2’s complement of a 2’s complement is the original number itself result indicates it is -1 in decimal. What do you mean by mixed mode arithmetic?
Associativity of operator can be left to right or right to left. For unary, compound assignment and ternary operator associativity is right to left for others it is left to right. Consider c=a+b+d; If two operators having same operator precedence occurs in a mathematical assignment statement then associativity starts playing its role. Since + operator has associativity from left to right therefore a+b will be evaluated first then result of a+b will be added to d and finally result of evaluation will be assigned to c. What is Control Structure? Control structure specifies the order in which the various instructions in a program are to be executed by the computer. There are four type of control structure or control statement:
execute this statement; The keyword if tells the compiler that what follows, is a decision control instruction. The condition following the keyword if is always enclosed within a pair of parentheses. If the condition, whatever it is, is true, then the statement is executed. If the condition is not true then the statement is not executed; instead the program skips past it. (b) if -else if statement by itself can execute only one statement if condition is true. If it required running a group of statements when condition is true we have to enclose those statements inside curly brace known as compound statement. The above form of if statement mentioned in (a) will not do anything when condition is false. If we want to run statement when condition is false we need if-else construct. General format of if-else construct is If (condition is true) Execute this statement; Else Execute this statement if condition is false; Condition is specified using relational operator x= =y means x is equal to y. x!= y means x is not equal to y. x< y means x is less than y. x>y means x is greater than y. x<=y means x is less than or equal to y. x>=y means x is greater than or equal to y What is the difference between = and = =? = operator is useful to assign value to some variable. = = operator is useful to compare value of variables or constant and can be used to build conditional expression.