Anda di halaman 1dari 21

EXCELLENT EDUCATIONS

PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C

FlowChar Vs Algorithm

An Algorithm is just a detailed sequence of simple steps that are needed to solve a problem. A Flowchart is a graphical representation of an algorithm.

Algorithm is step wise analysis of the work to be done. Flow chart is a pictorial representation of an algorithm. As flow chart is a picture of work to be done,it may be printed in our mind when we observe it. An algorithm is a fancy name for a set of rules to solve a problem, a flowchart is a diagram showing steps and decisions in a sequence. You could say a flowchart is a way of showing an algorithm in diagram form.

MODULAR PROGRAMMING:
Modular programming is a software design technique that increases the extent to which software is composed of separate, interchangeable components, called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish this.

Modularization is a method to organize large programs in smaller parts, i.e. the modules. Every module has a well defined interface toward client modules that specify how "services" provided by this module are made available. Moreover, every module has an implementation part that hides the code and any other private detail clients modules should not care of.

Modularization has several benefits, especially on large and complex programs:


modules can be re-used in several projects; changing the implementation details of a modules does not require to modify the clients using them as far as the interface does not change;

EXCELLENT EDUCATIONS

+91-98888-22427, 99143-17464

Success Notes for C PROGRAMMING faster re-compilation, as only the modules that have been modified are actually re-compiled;

self-documenting, as the interface specifies all that we need to know to use the module; easier debugging, as modules dependencies are clearly specified and every module can be tested separately; modern C compilers can generate faster and shorter executable programs, as they can freely reorganize private variable and functions, sometimes dropping them at all.

Programming by modules using the C language means splitting every source code into a header file module1.h and a corresponding code file module1.c. The header contains only declarations of constants, types, global variables and function prototypes that client program are allowed to see and to use. Every other private item internal to the module must stay inside the code file.

Header Files
A header file is a file containing C declarations and macro definitions (see Macros) to be shared between several source files. You request the use of a header file in your program by including it, with the C preprocessing directive `#include'. Header files serve two purposes.

System header files declare the interfaces to parts of the operating system. You include them in your program to supply the definitions and declarations you need to invoke system calls and libraries. Your own header files contain declarations for interfaces between the source files of your program. Each time you have a group of related declarations and macro definitions all or most of which are needed in several different source files, it is a good idea to create a header file for them.

Including a header file produces the same results as copying the header file into each source file that needs it. Such copying would be time-consuming and

EXCELLENT EDUCATIONS

+91-98888-22427, 99143-17464

Success Notes for C PROGRAMMING error-prone. With a header file, the related declarations appear in only one place. If they need to be changed, they can be changed in one place, and programs that include the header file will automatically use the new version when next recompiled. The header file eliminates the labor of finding and changing all the copies as well as the risk that a failure to find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with .h. It is most portable to use only letters, digits, dashes, and underscores in header file names, and at most one dot.
Example of Header file #include<stdio.h>

Explanation of #include<stdio.h>

The '#' sign tells the preprocessor, which scans the code before sending it to the compiler, to do something. "include" tells the preprocessor that the following file is to be included in the compiling process. When the compiler compiles the source code, it also compiles the file indicated, in the case a header file called "stdio.h" which contains macros and prototypes and variable types for input/output functions. Note that this doesn't actually link the functions to the executable, though the compiler might know to include the static library (.a or .lib) with the source code based on the header being included.

STACK:
A stack is a last in, first out (LIFO) data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack, or initializing the stack if it is empty, but if the stack is full and does not contain more space to accept the given item it is considered as an Overflow state (It means that the stack is overloaded or no more space for new item). The pop operation removes an item from the top of the stack, A pop either reveals previously concealed items, or results in an empty stack, but if the stack is empty then it goes under underflow state (It

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C


means no items are present in stack to be removed). The stack top operation removes the data from top most position without deleting it and returns it to user, the same underflow state can also occur in stack top operation if stack is empty. A stack is a restricted data structure, because only a small number of operations are performed on it. The nature of the pop and push operations also means that stack elements have a natural order. Elements are removed from the stack in the reverse order to the order of their addition: therefore, the lower elements are those that have been on the stack the longest.

APPLICATIONS OF STACK:
1-) to convert infix to post fix and prefix . 2-) to check wither a given string if palindrome or not. 3-) To evaluate post fix expiration . 4-) to check the right order of parenthesis of given expiration. 5-) Backtracking 6-) Memory Management 7-) Call & Return Process

PROGRAM TO PUSH AND POP IN STACK:


#define MAX 5 int top = -1; int stack_arr[MAX]; main() { int choice; while(1) { printf("1.Push\n"); printf("2.Pop\n"); printf("3.Display\n"); printf("4.Quit\n"); printf("Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1 : push(); break; case 2:

EXCELLENT EDUCATIONS
PROGRAMMING
pop(); break; case 3: display(); break; case 4: exit(1); default: printf("Wrong choice\n"); }/*End of switch*/ }/*End of while*/ }/*End of main()*/ push() { int pushed_item; if(top == (MAX-1)) printf("Stack Overflow\n"); else { printf("Enter the item to be pushed in stack : "); scanf("%d",&pushed_item); top=top+1; stack_arr[top] = pushed_item; } }/*End of push()*/ pop() { if(top == -1) printf("Stack Underflow\n"); else { printf("Popped element is : %d\n",stack_arr[top]); top=top-1; } }/*End of pop()*/ display() { int i; if(top == -1) printf("Stack is empty\n"); else { printf("Stack elements :\n"); for(i = top; i >=0; i--) printf("%d\n", stack_arr[i] ); } }

+91-98888-22427, 99143-17464

Success Notes for C

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C

LINKED LIST:
In computer science, a linked list (or more clearly, "singly linked list") is a data structure that consists of a sequence of nodes each of which contains a reference (i.e., a link) to the next node in the sequence. Linked lists are among the simplest and most common data structures. They can be used to implement several other common abstract data structures, including stacks, queues, associative arrays, and symbolic expressions, though it is not uncommon to implement the other data structures directly without using a list as the basis of implementation. The principal benefit of a linked list over a conventional array is that the list elements can easily be added or removed without reallocation or reorganization of the entire structure because the data items need not be stored contiguously in memory or on disk. Linked lists allow insertion and removal of nodes at any point in the list, and can do so with a constant number of operations if the link previous to the link being added or removed is maintained during list traversal.

LINKED LIST vs ARRAY:


It's easier to store data of different sizes in a linked list. An array assumes

every element is exactly the same size. As you mentioned, it's easier for a linked list to grow organically. An array's size needs to be known ahead of time, or re-created when it needs to grow. Shuffling a linked list is just a matter of changing what points to what. Shuffling an array is more complicated and/or takes more memory. As long as your iterations all happen in a "foreach" context, you don't lose any performance in iteration.

QUEUE:
A queue is a particular kind of collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once an element is added, all elements that were added before have to be removed before the new element can be invoked. A queue is an example of a linear data structure.

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C

CIRCULAR QUEUE:
A circular queue, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams.

A ring showing, conceptually, a circular buffer. This visually shows that the buffer has no real end and it can loop around the buffer. However, since memory is never physically created as a ring, a linear representation is generally used.

POINTER TO FUNCTION:
A function pointer can be used to invoke a function and pass it arguments just like a normal function. In programming languages like C, function pointers can be used to simplify code by providing a simple way to select a function to execute based on runtime values. Function pointers do always point to a function having a specific signature. Thus, all functions used with the same function pointer must have the same parameters and return type.
A function pointer is a variable that stores the address of a function that can later be called through that function pointer. This is useful because functions encapsulate behavior. For instance, every time you need a particular behavior such as drawing a line, instead of writing out a bunch of code, all you need to do is call the function. But sometimes you would like to choose different behaviors at different times in essentially the same piece of code. Read on for concrete examples.

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C

Function Pointer Syntax


void (*foo)(int);

C PREPROCESSOR:
The C preprocessor (cpp) is the preprocessor for the C programming language. In many C implementations, it is a separate program invoked by the compiler as the first part of translation. The preprocessor handles directives for source file inclusion (#include), macro definitions (#define), and conditional inclusion (#if). The language of preprocessor directives is agnostic to the grammar of C, so the C preprocessor can also be used independently to process other types of files. The transformations it makes on its input form the first four of C's so-called Phases of Translation. Though an implementation may choose to perform some or all phases simultaneously, it must behave as if it performed them one-by-one in order.

AUTO, STATIC, GLOBAL(EXTERN) variables: AUTO:


A auto or local variable is a variable which is defined within the scope of a function. This sort of variables are also called automatic variables. Automatic variables cannot retains its value once the function returns. That mean the scope and life of an automatic variable is within the function its defined in. Automatic variables are initialised by 0 automaticallu by the compiler at the time of compilation if those are not explicitly initialised by the programmer. Now an automatic/local variable is reinitialized everytime the function is called and destroyed once the function returns. Lets have an example: #include <stdio.h> void main(void) { int var = 0; /*explicit initialization*/var += 10; printf(Var = %d \n, var); } var is an automatic variable and is initialized to 0 at the beginning of the programm. Then its incremented by 10 and its value is printed. Well, as an automatic variable cannot retain its value once the function returns, everytime the function is called memory would be set aside for var in the stack of the function and var would be reinitialized to 0.

EXCELLENT EDUCATIONS
PROGRAMMING
STATIC:

+91-98888-22427, 99143-17464

Success Notes for C

Now imagine a condition when you want to keep track of an event occurring frequently in the system. What you want to do is to call a function, increment the previous value of the eventoccurring-counter, print its value and then return. To accomplish this you need to have a variable which can retain its value even after the function returns so that in the next call to the function the previous value of the counter could be incremented by one and so on. Astatic variable does the trick for you. A static variable can be of two types in nature: 1. 1. 1. static to the function. 2. static to the file. The above discussed static variable is of the first type. Well a static variable which is defined inside a function is not destroyed once the function returns and hence retains it value even after the function returns. The scope of this sort of static variable is within the function.A static variable of this sort cannot be called from outside the function. So its scope is just inside the function body.But even if its scope happens to be within the function its life is throughout the program execution which means that the variable still is in memory. A static variable can retain its previous value because it is not allocated from the stack. Its allocated from the data section of the memory. Uninitialized static variables are allocated form BSS(Block Started Symbol) section of the memory and initializes to 0 by default. Now lets discuss about the second type of static variable i.e. static variables defined inside a file but outside any function. These type of static variables are global to all the function in the particular file it is defined in i.e. any function can access the variable but any function outside the file cannot access it. These sort of variables cannot be extern -ed even. The following example show hows a gcc compiler throws error when you try to extern a static variable defined in a file.

EXTERN (GLOBAL)
Global variables are to be defined globally, e.g. at the beginning of the file(ofcourse out side all the functions in the file) or in a header file. Global variables retain value throughout the life of the program. A global variable can be accessed from any file with an external linkage. So the scope of a global variable is throughout the program. A global variable is allocated from the data section of the memory. Uninitialized global variable are allocated from the BSS section and initialized to 0 by default.

Syntax for EXTERN (GLOBAL) Variable:


#include<stdio.h> extern int var;

EXCELLENT EDUCATIONS
PROGRAMMING
main() { }

+91-98888-22427, 99143-17464

Success Notes for C

eXample of EXTERN(GLOBAL) Variable: test.c #include<stdio.h> extern int var;extern int foo(); main() { printf("value of var from foo: %d\n", foo()); printf("accessing var directly:%d\n ", var); } test1.c int var; /*global to this file and can be extern-ed by another file*/ int foo(void) { return ++var; }

PROBLEM ANALYSIS IN C:

Problem Analysis
If we are to use the computer as a problem-solving tool, then we must have a good analysis of the problem given. Here are some suggested steps on how to go about analyzing a certain problem for computer application: 1. Review the problem carefully and understand what you are asked to do. 2. Determine what information is given(input) and what result must be produced(output).

EXCELLENT EDUCATIONS
PROGRAMMING
3. Assign names to each input and output items.

+91-98888-22427, 99143-17464

Success Notes for C

4. Determine the manner of processing that must be done on the input data to come up with the desired output(i.e., determine what formulas are needed to manipulate the given data).

ALGORITHM & ITS CHARACTERISTICS: Algorithm:


An algorithm is an effective method expressed as a finite list[1] of well-defined instructions[2] for calculating a function.[3] Algorithms are used for calculation, data processing, and automated reasoning.

Characteristics:
Finiteness: terminates after a finite number of steps Definiteness: rigorously and unambiguously specified Input: valid inputs are clearly specified Output: can be proved to produce the correct output given a valid input Effectiveness: steps are sufficiently simple and basic.

With this definition, we can identify five important characteristics of algorithms. 1. 2. 3. 4. 5. Algorithms are well-ordered. Algorithms have unambiguous operations. Algorithms have effectively computable operations. Algorithms produce a result. Algorithms halt in a finite amount of time.

These characteristics need a little more explanation, so we will look at each one in detail.

EXCELLENT EDUCATIONS
PROGRAMMING Algorithms are well-ordered

+91-98888-22427, 99143-17464

Success Notes for C

Since an algorithm is a collection of operations or instructions, we must know the correct order in which to execute the instructions. If the order is unclear, we may perform the wrong instruction or we may be uncertain which instruction should be performed next. This characteristic is especially important for computers. A computer can only execute an algorithm if it knows the exact order of steps to perform. Algorithms have unambiguous operations Each operation in an algorithm must be sufficiently clear so that it does not need to be simplified. Given a list of numbers, you can easily order them from largest to smallest with the simple instruction "Sort these numbers." A computer, however, needs more detail to sort numbers. It must be told to search for the smallest number, how to find the smallest number, how to compare numbers together, etc. The operation "Sort these numbers" is ambiguous to a computer because the computer has no basic operations for sorting. Basic operations used for writing algorithms are known as primitive operations or primitives. When an algorithm is written in computer primitives, then the algorithm is unambiguous and the computer can execute it. Algorithms have effectively computable operations Each operation in an algorithm must be doable, that is, the operation must be something that is possible to do. Suppose you were given an algorithm for planting a garden where the first step instructed you to remove all large stones from the soil. This instruction may not be doable if there is a four ton rock buried just below ground level. For computers, many mathematical operations such as division by zero or finding the square root of a negative number are also impossible. These operations are not effectively computable so they cannot be used in writing algorithms. Algorithms produce a result In our simple definition of an algorithm, we stated that an algorithm is a set of instructions for solving a problem. Unless an algorithm produces some result, we can never be certain whether our solution is correct. Have you ever given a command to a computer and discovered that nothing changed? What was your response? You probably thought that the computer was malfunctioning because your command did not produce any type of result. Without some visible

EXCELLENT EDUCATIONS

+91-98888-22427, 99143-17464

Success Notes for C PROGRAMMING change, you have no way of determining the effect of your command. The same is true with algorithms. Only algorithms which produce results can be verified as either right or wrong.

Algorithms halt in a finite amount of time Algorithms should be composed of a finite number of operations and they should complete their execution in a finite amount of time. Suppose we wanted to write an algorithm to print all the integers greater than 1. Our steps might look something like this: 1. Print the number 2. 2. Print the number 3. 3. Print the number 4. . . . While our algorithm seems to be pretty clear, we have two problems. First, the algorithm must have an infinite number of steps because there are an infinite number of integers greater than one. Second, the algorithm will run forever trying to count to infinity. These problems violate our definition that an algorithm must halt in a finite amount of time. Every algorithm must reach some operation that tells it to stop.
NULL STATEMENT
A "null statement" is a statement containing only a semicolon; it can appear wherever a statement is expected. Nothing happens when a null statement is executed. The correct way to code a null statement is:
;

Examples of Null Statements The following example initializes the elements of the array price. Because the initializations occur within the for expressions, a statement is only needed to finish the for syntax; no operations are required. for (i = 0; i < 3; price[i++] = 0) ;

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C


A null statement can be used when a label is needed before the end of a block statement. For example: void func() { if (x) goto depart; /* further processing */ depart: ; }
STEPWISE REFINEMENT:

Step-wise refinement
The objective of the design methodology is to first establish the overall structure and the relationships between the various parts of the problem, and then address the specific and complex issues of the implementations of the various sub-parts. The main phases of computer based problem solving are: Outline of solution: which identifies the basic principle by which the input can be transformed to the output and gives an outline of the solution. Algorithm design and analysis: which makes precise the outline indicated, identifies the various components required and gives a precise method of computing the solution. A crucial aspect in algorithm design is the analysis of correctness and efficiency. Program design: which involves an implementation of the algorithm using the syntax of a programming language. StepwiseRefinement is a technique of SoftwareDesign that has been successfully used in a wide range of StructuredProgramming and ModularProgramming envir onments and languages. It is the procedural (step-bystep) form of SeparationOfConcerns. The advantage of StepwiseRefinement is that it allows for IncrementalDevelopment but on a much finer level of granularity.

EXCELLENT EDUCATIONS
PROGRAMMING PRINCIPLES OF STEPWISE REFINEMENT

+91-98888-22427, 99143-17464

Success Notes for C

In order to verify complex systems against their requirements one needs intermediate levels of abstraction. This can be achieved best by deriving a system formally by stepwise refinement. Starting from the requirements, at each step one constructs a more concrete description of the system and verifies it against the specification constructed in the previous step until one arrives at the implementation. The focus of my talk is on the question what refinement means formally. Various refinement concepts have been proposed in the literature. I will identify basic principles which are common to many of the existing refinement concepts. The running example will be a well-known refinement concept which assumes that systems are modeled by sets of traces.
BASIC C CONSTRUCTS:

o o

1 Loops 2 Simple I/O 2.1 Standard input/output 2.2 File reading writing 3 Command line arguments

COMMAND LINE ARGUMENTS:

In environments that support C, there is a way to pass command-line arguments or parameters to a program when it begins executing. When main is called, it is called with two arguments. The first (conventionally called argc, for argument count) is the number of command-line arguments the program was invoked with; the second (argv, for argument vector) is a pointer to an array of character strings that contain the arguments, one per string. We customarily use multiple levels of pointers to manipulate these character strings. By convention, argv[0] is the name by which the program was invoked
#include <stdio.h> main( int argc, char *argv[] ) {

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C


if( argc == 2 ) printf("The argument supplied is %s\n", argv[1]); else if( argc > 2 ) printf("Too many arguments supplied.\n"); else printf("One argument expected.\n");

MACRO:

A preprocessor line of the form


#define name text

defines a macro with the given name, having as its value the given replacement text. After that (for the rest of the current source file), wherever the preprocessor sees that name, it will replace it with the replacement text. The name follows the same rules as ordinary identifiers
The C preprocessor (cpp) is the preprocessor for the C programming language. In many C implementations, it is a separate program invoked by the compiler as the first part of translation. The preprocessor handles directives for source file inclusion (#include), macro definitions (#define), and conditional inclusion (#if). The language of preprocessor directives is agnostic to the grammar of C, so the C preprocessor can also be used independently to process other types of files. The transformations it makes on its input form the first four of C's so-called Phases of Translation. Though an implementation may choose to perform some or all phases simultaneously, it must behave as if it performed them one-by-one in order.

Dynamic memory allocation:


The process of allocating memory at run time is known as dynamic memory allocation. Although c does not inherently have this facility there are four library routines which allow this function.

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C


Many languages permit a programmer to specify an array size at run time. Such languages have the ability to calculate and assign during executions, the memory space required by the variables in the program. But c inherently does not have this facility but supports with memory management functions, which can be used to allocate and free memory during the program execution. The following functions are used in c for purpose of memory management.

Function Task Allocates memory requests size of bytes and returns a pointer to the Ist byte of allocated space Allocates space for an array of elements initializes them to zero and returns a pointer to the memory Frees previously allocated space

malloc

calloc free realloc

Modifies the size of previously allocated space.

Typecasting
Typecasting is a way to make a variable of one type, such as an int, act like another type, such as a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. Example
int main() { printf( "%c\n", (char)65 ); }

BINARY TREE :
A binary tree is made of nodes, where each node contains a left pointer, a right pointer, and a data element. The root pointer points to the topmost node in the tree. The left and right pointers recursively point to smaller subtrees on either side.

EXCELLENT EDUCATIONS
PROGRAMMING Here is an example of a tree holding letters:
tree ---j / \ \ h

+91-98888-22427, 99143-17464

Success Notes for C

<-- root k \ z <-- leaves

f a /

BINARY TREE IMPLEMENTATION:


struct node { int data; struct node* left; struct node* right; }

Application of TREE:
1. Manipulate hierarchical data. 2. Make information easy to search (see tree traversal). 3. Manipulate sorted lists of data. 4. As a workflow for compositing digital images for visual effects. 5. Router algorithms

Procedure-oriented programming
A type of programming where a structured method of creating programs is used. With procedure-oriented programming, a problem is broken up into parts and each part is then broken up into further parts. All these parts are known as procedures . They are separate but work together when needed. A main program centrally controls them all. Some procedure-oriented languages are COBOL, FORTRAN, and C.

Object oriented programming


A type of programming where data types representing data structures are defined by the programmer as well as their properties and the things that can be done with them. With object-oriented programming, programmers can also create

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C


relationships between data structures and create new data types based on existing ones by having one data type inherit characteristics from another one. In object-oriented programming, data types defined by the programmer are called classes (templates for a real world object to be used in a program). For example, a programmer can create a data type that represents a car - a car class. This class can contain the properties of a car (color, model, year, etc.) and functions that specify what the car does (drive, reverse, stop, etc.) Some object-oriented languages are C++, Java, and PHP.

TOP DOWN & BOTTOM UP PROGRAMMING


Top down Program Design : Begins the design with main or top-level module, and progresses downwards to the lowest level modules or subsystem Bottom down Program Design : Begins the design with the lowest level modules or subsystems, and progresses upward to the main program, module or subsystem.

Top-down and bottom-up are strategies of information processing and knowledge ordering, mostly involving software, but also other humanistic and scientific theories (see systemics). In practice, they can be seen as a style of thinking and teaching. In many cases top-down is used as a synonym of analysis or decomposition, and bottom-up of synthesis. A top-down approach (also known as step-wise design) is essentially the breaking down of a system to gain insight into its compositional sub-systems. In a top-down approach an overview of the system is formulated, specifying but not detailing any firstlevel subsystems. Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. A top-down model is often specified with the assistance of "black boxes", these make it easier to manipulate. However, black boxes may fail to elucidate elementary mechanisms or be detailed enough to realistically validate the model. A bottom-up approach is the piecing together of systems to give rise to grander systems, thus making the original systems sub-systems of the emergent system. In a bottom-up approach the individual base elements of the system are first specified in

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C


great detail. These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed. This strategy often resembles a "seed" model, whereby the beginnings are small but eventually grow in complexity and completeness. However, "organic strategies" may result in a tangle of elements and subsystems, developed in isolation and subject to local optimization as opposed to meeting a global purpose.

RECURSION:
Recursion is when a function calls itself. The alternative is iteration. However, recursive solutions to problems are sometimes simpler than iterative ones. But recursion is less efficient and can use significantly more memory because all of the function calls to itself get pushed onto the stack. Example (Factorial through Recursion) int factorial(int a) { if (a == 1) return 1; else { a *= factorial(a-1); return a; } }

ENUM (ENUMERATION)
Short for enumeration, an enum variable type can be found in C . The idea is that instead of using an int to represent a set of values, atype with a restricted set of values in used instead. For example if we use the colors of the rainbow, which are 1. Red 2. Orange 3. If enums didn't exist, you might use a #define (in C) or const in C++/C# to specify these values. Eg #define red 1 #define orange 2

EXCELLENT EDUCATIONS
PROGRAMMING

+91-98888-22427, 99143-17464

Success Notes for C

DEEPLY EXPLORE: Call By Value & Ref. Variable, Keyword, Data Type, Identifier Diff Bw Array, Structure, Union, Linked List, Queue, Stack Dynamic Memory Allocation Control Statement FILE OPENING MODES BINARY vs TEXT FILES, BREAK & CONTINUE Short Ques Put() Puts() Gets() Putchar() Getchar()

Anda mungkin juga menyukai