Search This Blog

Thursday, 15 December 2011

Valids Points to Remember on C!

0 comments

POINTS TO REMEMBER IN C PROGRAMMING!
  1. C is a general-purpose structured programming language developed by Dennis Ritchie
  2. An identifier is a string of alphanumeric characters that begins with an alphabetic character or an underscore character that are used to identify or name various programming elements such as variables, functions, arrays, structures, unions and so on.
  3. Keywords are the words, which have fixed meanings that has been already defined in the C compiler. They can be used only for their intended purpose and can’t be used as user-defined variables
DATA TYPES
  1. Data types supported in a language dictates the type of vales, which can be processed by the language, The primary data types are char, int, float and double.
  2. Type definition allows the user to define new data types that are equivalent to existing data types.
  3. The enum data type given as opportunity to define our own data type with a set of named integer constants.
CONSTANTS
  1. Constant in C refers to fixed values that don’t change during execution of a program.
  2. An integer constant refers to sequence of digits without a decimal point.
  3. A character constant contains a single character enclosed within a pair of single quotes.
  4. A character string or a string constant or a literal consists of a sequence of characters enclosed in double quotes. It may contain any number of digits, letters, escape sequences, and space.
  5. The end of a string constant is marked with a single character referred as the NULL character.
VARIABLES
  1. A quantity which may vary during the execution of a program is called as a variable.
  2. Variables that can’t be changed by a function in which it is present or by any other function in the same program are called constant variables.
  3. To store more than one value in a variable, use arrays that refer to a group of data items, which share a common name with the same data type.
OPERATORS
  1. An operator is a symbol or a special character that tells the compiler to perform certain mathematical and/or logical operations.
  2. Modulo division produces the remainder of an integer division as its result. Modulo division is used only between integers.
  3. The sizeof operator is a keyword which returns the size of its operand in bytes.
  4. The conditional operator denoted by (?:) is used to evaluate conditional expressions.
STATEMENTS IN C
  1. A statement in a program carries out some specific action. Statements used in C are classified as expression, compound and control statements.
  2. An expression statement consists of valid C expressions, ending with a semicolon.
  3. A group of valid C expressions statements placed within an opening curly brace ‘{‘ and a closing curly brace ‘}’ is referred as a compound statement.
STANDARD LIBRARY FILES
  1. The standard library is not a part of the C language but an environment which provides function declarations, type and macro definitions for the standard C language.
  2. Comment statements used in a program must be enclosed within /* and */. They may or may not be present in a program. Comment statements improve the readability of a program.
  3. The preprocessor directive #include <stdio.h> refers to a special file which contains the information about the various standard input and output operations which must be included in the program when it is compiled.
SYNTAX OF C PROGRAM
  1. Every C program must contain at least one function, which must be a main. A program will always begin by executing the main() function.
  2. White space characters between printf, scanf and other expression statements are usually encouraged as a good programming practice.
  3. The main() function consists of two parts namely the declaration part and the execution part. Both these parts should appear between the opening and closing braces of the function.
  4. All variables must be declared in the program before they are used in the executable statements.
  5. All statements used in both declaration and executable parts must end with a semicolon compulsorily.
INPUT/OUTPUT FUNCTIONS
  1. The formatted input/output functions read any type of data as input from the user and display any type of data as output in the screen. They use format strings (also referred as conversion specifiers) for identifying the type of the data involved.
  2. All unformatted input/output functions read and display only char data type. They don’t use format strings for identifying the type of the data involved, since all data are considered as characters.
  3. The scanf() function is usually called as input statement, which reads formatted input from the user through keyboard. It reads input from the user till it encounters a space or the end of conversion specifier specified in the statement.
  4. The printf() function is usually called as the output statement, which displays formatted output on the screen.
  5. The functions - getchar(), getch() and getche() deal with single character input. Whereas the function putchar() deals with single character output.
  6. The gets() function reads input from the user till it encounters a new line character.
  7. The scanf() function can read any number of characters, integers, strings and floats at a time, whereas the gets() function can read only one string at a time.
  8. The gets() and puts() functions deal with string input and output respectively.
ARRAY IN C
  1. An array is a group of elements of same data type that share a common name and that are differentiated from one another by their positions within the array. The individual vales in the array are called as elements.
  2. The array name should be unique and should be a valid C identifier.
  3. Each element in an array is referred by specifying the array name followed by one or more subscripts enclosed in square braces.
  4. A subscript must always be a positive integer or an integer expression.
  5. Arrays can be initialized to the same type with which they are declared.
  6. It is an error to specify more initializers than the number of elements in the array.
  7. It is not necessary to specify the length of an array, explicitly in case if initializers are provided for the array during declaration itself.
  8. A character array can be initialized by a string constant, result in the first element of the array being set to the first character in the string, the second element to the second character and so on. The array also receives the terminating ‘\0’ in the string constant.
  9. Arrays whose elements are specified by one subscript are called one dimensional array or single dimensional or single subscripted or linear arrays. It is also called as a list.
  10. Array whose elements are specified by two subscripts are called as two dimensional arrays or double dimensional arrays. It is also called as a matrix.
  11. The number of elements in a multi-dimensional array is the product of its subscripts.
STRING MANIPULATION IN C
  1. Any copy of characters specified within double quotes is a string constant.
  2. Strings can be read through scanf() and gets() functions. They can also be read character by character using functions scanf() and getchar().
  3. The strlen() function returns the number of characters present in a string.
  4. The strcpy() function copies the contents of one string into another string.
  5. The strcat() function concatenates the second string with the content of the first string.
  6. The strcmp() function compares two strings to find whether the strings (passed as arguments) are equal or not.
  7. The strrev() function reverses the string passed as an argument.
  8. The strlwr() function converts the string to lowercase.
USING POINTERS IN C
  1. A pointer is a variable that represents the memory location (not the value) of a data item such as a variable or an array element.
  2. Like all variables, a pointer should also be declared before they are used.
  3. The ampersand operator (&) gives the address of a variable.
  4. The three values that can be used to initialize a pointer are zero, null and address.
  5. A pointer that has not been initialized is referred to as the dangling pointer.
  6. The arithmetic operations that are performed on pointers are addition and subtraction.
  7. Arguments to a function are passed in two ways. They are: call by value and call by reference. Call by value is the process of passing the actual value of a variable.
  8. Call by reference is the process of calling a function using pointers, which passes the address of the variable passed as parameter. Any changes made in the argument reflect in the actual parameter passed during function call.
  9. Arrays are automatically passed by reference since the value of the array name is the pointer to the array.
  10. The malloc() function is used to allocate a contiguous block of memory in bytes and returns the starting address of the memory to the user.
  11. The calloc() function is used to allocate multiple blocks of contiguous memory in bytes and returns the starting address of the memory to the user. All the blocks are of same size.
  12. The realloc() function is used to increase or decrease the size of the memory already allocated by malloc() or calloc() functions.
  13. The free() function is used to release or deallocate() the block of unused or already used memory.
STRUCTURE AND UNION IN C
  1. A Structure is a derived type usually representing a collection of variables of same or different data types grouped together under a single name.
  2. The keyword struct begings the structure declaration followed by the structure name, the structure members are enclosed in braces, followed by a semicolon, which ends the structure declaration.
  3. A structure definition creates a new data type that can be used to declare variables.
  4. The variables or data items in a structure are called as members of the structure.
  5. Usually the structure type declaration appears at the top of the source code files, before any variables or function are defined.
  6. The tag name for a structure is optional. If the structure is defined without a tag name, the variables of the derived data type must be declared in the structure definition, and no other variables of the new structure can be declared.
  7. A structure variable may be initialized with a structure variable of the same type.
  8. A member of a structure is always referred and accessed using the member access operator via the structure variable name.
  9. A structure that contains another structure as its member is called as nesting of structures.
  10. Array of structures are defined as a group of data of different data types stored in consecutive memory locations with a common variable name. We can also use arrays as structure members.
  11. A structure containing a member that is a pointer to the same structure type is called as a self-referential structure.
  12. The structure pointer operator (-->) is used for accessing a member of a structure via a pointer to the structure.
  13. A bit field is a built-in feature that allows us to access a single bit. They must be defined as a member of a structure and declared as type unsigned or int.
  14. Each bit field can then be accessed individually similar to other members of a structure. They enable better memory utilization for storing the data in the minimum number of bits required.
  15. A union is another compound data type like a structure that may hold the variables of different types and sizes, with the compiler keeping track of the size.
  16. The keyword union begins the union declaration followed by the tag (i.e., union name), within the braces, union members are declared.
  17. A union may contain many members of different types, but the memory space reserved for a union is large enough to store its largest member.

Leave a Reply