Вы находитесь на странице: 1из 14

Q.

Write short notes on following

*Features of CC has following important features: 1) A simple core language, with important functionality such as math functions or file handling provided by sets of library routines instead. 2) Focus on the programming model, with facilities for programming in structured style. 3) A simple type system which prevents many operations that are not meaningful. 4) Use of processor language, the C processor, for task such as defining macros & including multiple source code files. 5) Low level unchecked access to computer memory via the use of pointer. 6) Parameters that are always passed to function by value never by reference. 7) Lexical variable scoping. 8) Records or user defined aggregate data types (structures) which allow related data to be combined & manipulated as a whole.

*AlgorithmAlgorithm is a finite sequence of instructions which can be carried out to solve particular problem in order to obtain desired result. For any computer program steps required for processing are very important. To produce an efficient or effective computer program one must plan the logic of program. Algorithm represents the logic of the processing to be done. Characteristics & capabilities1) 2) 3) 4) 5) Instructions/steps must be precise & unambiguous. Every instruction should be performed infinite time. The algorithm should be alternately terminated. The desired results should be obtained after the algorithm terminates. The algorithm should produce one or more outputs which are obtained after processing.

Capabilities 1) 2) 3) 4) 5) 6) They are simple but powerful & general solution. They can be easily modified if necessary. They are correct for clearly defined solution. They are not dependent being run on particular computer. They are able to used as a sub-procedure for other problems. The solution is pleasing & satisfying to its designer.

*Pointers in cA pointer is a variable thet points to another variable. This means pointer is a special kind of variable that holds the memory address of another variable . in other words , it points to other variable by holding its address. Pointer operators1) * enables the associated variable capable of storing address variables. 2) & returns the address of associated variables. Declaration & initializing a pointer variable Initializing at a time of declaration, Datatype *ptr_name=address of another variable e.g. int *p=&x; Initializing after declaration, Datatype *ptr_name; Ptr_name=address of another variable; e.g. int *p; p=&x; Importance & Application of pointerIn computer an address is more important than value . Variable of an ordinary data types can not process address. So knowledge of pointer is a must to get full advantage of power of C. Pointers are used to create dynamic data structures. C uses pointers to handle variable parameters passed to functions. another

Pointers in c provides an alternative means of accessing information stored in arrays, which is specially valuable when you work with string.

*File operationsA file in computer system is a stream of bits stored as a single unit ,typically in a file system on disk or magnetic tape & given a name. The file operations are as follows: 1) Creating a file: 2) Opening a file: (open can also means creating a file) The file can be opened with fopen function. This function will tell operating system to open the file & it will return the file pointer. Myfile=fopen(filename,mode); e.g. mufile=fopen(abc.txt,r); 3) Reading from file: C provides functions to read data from file. fgetc() Read character from file fgets() Read string from file getw() Read integer from file fscanf() Read formatted i/p from file. 4)writing to a file: C provides functions to write data to file. fputc() Read character from file fputs() Read string from file putw() Read integer from file fprintf() Read formatted o/p from file. 5)closing a file: Once you finished all the operations you need to close the file using fclose() function. At the end of the file EOF character is written. e.g. fclose(myfile);

*Formatted i/p & o/pprintf()-(Formatted o/p) printf() generates output under the control of format string which consist of literal characters to be printed. printf() is a versatile o/p, which can handle any built in data type & you can specify the format in which data must be displayed. Syntax: printf(control string,arg1,arg2,.,arg n); Where control string refers to string that contains formatic information. Arg1,arg2, are arguments that represents the individual output data items. The arguments can be written as constants, single variable or array names or complex expressions. The arguments in a printf() do not represents memory address & therefore are not preceded by ampersand. Character conversionCharacter c d s o f e meaning data item is displayed as single character data item is displayed as decimal integer data item is displayed as string data item is displayed as octal integer data item is displayed as floating point having without an exponent data item is displayed as floating point having with an exponent

scanf()-(formatted output)Input data can be entered into the computer from a standard i/p device by means of the C library function scanf(). Using this function you can accept any combination of numerical values ,single characters & string. It reads character from the standard i/p device , interpret them according to the format specifiers & stores them in the corresponding arguments or variables. Syntax:

Scanf(control string,&var1,&var2,..&varn); Where control string consist of a) white space character b) conversion specification which consist of a % sign & a conversion character Character conversionCharacter c d s o f e meaning data item is displayed as single character data item is displayed as decimal integer data item is displayed as string data item is displayed as octal integer data item is displayed as floating point having without an exponent data item is displayed as floating point having with an exponent

*Dynamic memory allocationMost of the times in the real time scenario you find that data is dynamic in nature & you may not be able to predict the no. of data items at the time writing the program itself.e.g. when you are writing program for railway ticket booking you may not know no. of tickets that will be issued at the time of writing program itself. Let us consider another program that process a list of customers. The list grows when you are having more customer & the list shrinks when you are having few customer. So, when the list grows you need to allocate more amount of memory space to accommodate additional Customers. In this situation we can not use arrays to share customer details because the size of arrays is fixed & needs to be specified at the time of declaring the array & can not predict the no of customer you are going to handle at the time of writing the program. So array doesnt serve our purpose. The above mentioned situations can be handled more easily & more effectively by using dynamic memory allocation. Dynamic memory allocation. Dynamic memory

allocation permits us to allocate additional memory space or to release unwanted memory at the time of program execution , thus optimizing memory management. C provides a set of functions in detail. Memory allocation process: Local variables Free memory Global variable C pro . instructions Permanent storage area

stack Heap

The program instructions & global and static variables are stored in region known as permanent storage area. And local variables are stored in stack area. The memory location that is there between these two regions is used for dynamic allocation of memory during program execution & this area is referred as Heap. All the four functions malloc(), calloc() ,free() ,realloc() will operate in this area. Functions for dynamic M. A. Function Task

1)malloc()

Allocate requested size of bytes & returns a pointer to the 1st byte of allocated memory. Allocate space for array of elements, initializes them with zero & returns a pointer to alloacated memory Modifies the size of previously allocated memory. Frees the previously allocated memory

2)calloc()

3)realloc() 4)free()

1)e.g. of malloc() Type_ptr=(cast_type *)malloc(byte_size) as int_ptr=(int *)malloc(10 *sizeof(int)); 2)e.g. of calloc() Type_ptr=(cast_type *)calloc(n ,element_size) as char ptr=(char *)malloc(10 *sizeof(arr)); 3)e.g. of realloc() int *ptr=malloc(10 *sizeof(int)); ptr=realloc(ptr,20 *sizeof(int)); 4) e.g. of free() free(pointer variable); as free(ptr);

*Program of Union#include<stdio.h> #include<conio.h> Void main() { Union sample { int a; char b; float c; }; union sample s; clrscr(); /*stored intger & retrieved as integer */

s.a=10; printf(a=%d,s.a); s.a=x; printf(a=%c,s.b); s.a=100.34; printf(a=%.2f,s.c); s.a=1.567; printf(a=%d,s.a); getch(); } o/p a=10 b=x c=100.34 a=-27787

*FlowchartFlowchart is a symbolic representation of step by step manner(solution) of a given problem & it indicates the flow of the entire process , the sequence of data i/p, operations, computations, decisions, result & other relevant information ,pertaining to a particular problem. Kinds of flowchart: 1)System flowchart - used by system analyst 2)program flowchart used by programmers

Symbols:

Terminal point

process

Predefined process

desicion

flowline

i/p o/p

connector

Document

Advantages of flowchartI. it is the convenient method of communication. II. It indicates very clearly just what is being done,where as a program has logical complexity. III. It is a key to correct programming. IV. Ia is an important tool for planning & designing new system. V. It clearly indicates a role played at each level. VI. It saves the inconvenience in future & serves the purpose of documentation for a system. VII. It facilates trouble shooting & promote logical accuracy VIII. It makes sure that no logical path is left incomplete without any action being taken.

Unconditional Control statement-

1)Beark` An early exit form a loop can be accomplished by using break statement (we have already used to break statement with switch.case).The break statement can be used even with any of the looping structures. When break statement is encountred inside a loop, the loop gets terminated & program control is transferred to the statement that is after a loop. In case of nested loops, when you use break inside a inner loop, it causes exit from the inner loop & program control is transferred to the outer loop. If the break statement is used in outer loop, the program control is passed to the statement that is next to the loop. e.g. while(test condition) { .; .; if(condition) break; .; } Statements;

2)gotoThe goto unconditionally transfers the program control from one point to another point within the program , it uses a lable in order to identifythe place where the program control needs to be transferred. A lable is valid identifier name & must be followed by a colon(:). e.g. lable: goto lable; .; statement; .; ..; goto lable; .; lable: statement;

we must be very careful while using goto because it may results inti uninterrupted loops or complexity in program manageability.

3) continuec supports another statement called continue which causes the loop to be continued with the next iteration, skipping a portion of the loop. e.g. while(test condition) { .. .. If(condition) continue; . } Statements; do { . if(condition) continue; } while(condition) statements;

As shown above continue statement causes the program control to be directly transferred to the test condition & them causes the early iteration of the loop.

*control statements1)decision/selection/branching statement(i) If (ii)If.else (iii) nested if (iv) switch statements 2) looping/Iteration statement(i) while statements (ii)do statement (iii) for statement

*sizeof operator-

The sizeof operator gives the amount of storage in bytes, required to an object of type of operand. The operator allows you to avoid specifying machine-dependent data sizes in your programs. sizeof unary_expression or sizeof (type_name) The operand is either an identifier that is unary-expression, or a type. The result is an unsigned integral constant. When you apply the sizeof operator to a structure or union type name or to an identifier of structure or union type,the result is the number of bytes in the structure or union. e.g. sizeof(int) returns 2(bytes) on 16-bit compiler & returns 4(bytes) on 32-bit compiler.

*IdentifiersIdentifiers are the name given to various programming elements( variables,arrays,functions,etc.) in a program by the programmer. Identifiers are the fundamental requirements of any programming language & each language has its own rule for naming. Rules: 1) 2) 3) 4) mane must be sequence of letters, digit & underscore. 1st character can not be digit. Uppercase lowercase letters are distinct. Name length-32 chararcter.

*keywordsKeywords are reserves identifiers & have predefined meaning to compiler. They can not be used as name for the user defined programming. They are always written in lower case. e.g. auto double int struct break register long switch void return typedefunion ..

*typedef specifier-

A typedef declaration introduces a name that within its scope, becomes a synonym for the type given by the type declaration portion of the declaration. Syntax: typedef type_declaration synonym; e.g. typedef int marks; Now onwards you can use the identifiers marks to declare variable of type int. marks m1,m2; we can use typedef declarations to construct shorter or more meaningful names for type already defined by the language or for types that you have declared. In contrast to the struct, union & enum declarations, typedef declaration do not introduce new types-they introduce new names for existing types. e.g. #include<stdio.h> typedef int marks; main() { marks m1,m2; m1=10; m2=20; printf(\n Total marks=%d\n,m1+m2); }

*fseekThe fseek() function repositions the file pointers of a stream. It is declared as, Int fseek(FILE *stream,long offset,int start); The fseek() function sets the file pointer associated with stream to a new position. The FILE *stream is the stream whose file pointer fseek() sets. The offset is the difference in bytes between start & the new position. The start is one of the three SEEK_XXX file pointer location(0,1,or 2) Constant SEEK_SET Value 0 File location Seeks from begening of the file

SEEK_CUR SEEK_END

1 2

Seeks form the current position Seeks from the end of the file

*ftellThis function ftell(), returns the current filoe pointer. It is declared as, long int ftell(FILE *fp); It returns the current file pointer for fp. The offeste is measured in bytes from the beginning of the file. On success it returns the current file pointer position. On error, it returns -1L & sets errorno to appositive value. s

Вам также может понравиться