C cheat Sheet - Part 1

General:

  1. ++ or -- cannot be used on enum value.
  2. sprintf could be used to convert an int or float to a string
  3. free() frees the memory during run time
  4. fflush() flushed all the streams and the specified streams.
  5. randomize(): returns a random number generator with a random value based on time.
  6. fprintf- Can be used to print the output to the screen.
  7.  '\o' is called as NULL in AScii
  8. ftell() tells the current position in the file stream
  9. frewind() goes to the start of the file.
  10. The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and string handling, in the C programming language. The C standard library is an interface standard described by a document; it is not an actual library of software routines available for linkage to C programs.
  11. Hence, standard library is not a part of C package.
  12. fmod performs floating point divisions. Hence you cannot use % operator on the float.
  13. Types of linkages: Internal, External, and None
  14. By Default a real number is treated as double
  15. If we use extern as a qualifier then we should declare it outside.
  16. Any pointer size is 2 bytes. (only 16-bit offset)
    1. a.     So, char *s1 = 2 bytes.
    2. b.     So, char far *s2; = 4 bytes.
    3. c.     So, char huge *s3; = 4 bytes.
  17. A far, huge pointer has two parts: a 16-bit segment value and a 16-bit offset value.
  18. Since C is a compiler dependent language, it may give different at different platforms. The above program works fine in Windows (TurboC), but error in Linux (GCC Compiler).
  19. When an automatic structure is partially initialized remaining elements are initialized to 0(zero).
  20. When an automatic array is partially initialized, the remaining elements are initialized to 0
  21. Yes, In all the global variable declarations, you need to use the keyword extern. And it has only one definition
  22. In 16 bit compiler, the pointer size is always 2 bytes.
  23. In 32 bit compiler, the pointer size is always 4 bytes.
  24. sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes
  25. sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.
  26. sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.
  27. Recurrence relations are used to find the big Oh of the recursive functions
  28. Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.
  29. 16-bit compiler will generate the machine code that is targeted to work for 16-bit microprocessor
  30. Highest bit is used to store the sign of the integer.
  31. Long int/ long(Atleast 4)
    1. Short int/short (atleast 2 bytes)
    2. Ints never bigger than longs
  32. If the constant value is small to be satisfied by int but we want more storage so we can have
    1. a.     Int I = 23L.          //This will assign more space to it.
  33. Signed and unsigned:
    1. Signed int i
    2. Signed I; //Default is signed.
  34. Signed and unsigned int;
  35. Signed and unsigned char;
  36. Signed and unsigned float
  37. In case of signed if we assign a character that has int value greater than 127 then rollover happens and value from the other side gets assigned to it.
    1. When we attempted to store 128 in char then the negative value get stored in char\
    2. If we exceed range on positive side we end up on negative side and vice versa.
  38. Int has 2/4 bytes of memory.
  39. Long = 4 bytes of memory
  40. Short = 2 bytes of memory
  41. Float = 4 bytes of memory
  42. Double = 8 bytes of memory
  43. Char = 1 bytes of memory
  44. Long double = 10 bytes
  45. Data types: Summary
    1. Signed int
    2. Unsigned int
    3. Short signed int
    4. Short unsigned int
    5. Long signed int
    6. Long unsigned int
    7. Signed char
    8. Unsigned char
    9. Float
    10. Double
    11. Long double
  46. The size of int, char, float is compiler dependent
  47. The negative numbers are stored in 2C format.
  48. FILE - a structure containing the information about a file or text stream needed to perform input or output operations on it, including:
    1. a file descriptor, the current stream position,
    2. an end-of-file indicator,
    3. an error indicator,
    4. a pointer to the stream's buffer, if applicable
Functions:

  1. In functions there is no precedence
  2. main() can be called from some other functions.
    1. For ex: a() { main()}
  3. One function cannot be defined in another
  4. Each function perform some isolated task.
  5. 2 types of functions:
    1. Library - Same type of functions are grouped together
      1. They reside on the disk.
      2. Written by people, who write compilers 
    2. User Defined
  6. The number, type, and order of formal and actual arguments should be same.
  7. They(Actual & Formal) are treated as different by the compiler.
  8. return; //It will return the garbage values
  9. return(10,20); //Not allowed
  10. Pass by value:
  11. When the formal arguments are passed to the actual arguments. Then the arguments are not passed. Only the photocopy is passed.
  12. Formal arguments and local variables are defined inside the stack.
  13. Standard Calling convention:
    1. Arguments are passed in the Right to Left order.
  14. func(int a, int b)
    1. func(1,2); => b = 2 && a = 1
  15. Stack is cleaned up by the called function: For ex:
    1. Main() { Func(); //This function cleans up the stack }
  16. If the return type is not specified then int is assumed by default.
  17. The address cannot be negative. Hence, we can’t have sign associated with it. Hence %u.
  18. **p: A pointer, which contains another pointer address, which in turn contain the address of either int/char/float.
  19. Address are always whole numbers. Hence pointers cannot have floating point numbers.
  20. Compilers use stack for normal and recursive function calls.
  21. Whenever, we make a recursive calls. The parameters and the return address get pushed to the stack
  22. If we don’t have a base condition for the function then soon the stack will overflow and runtime error: stack overflow will come.
  23. Whenever, we compile the code we get object file. .c to .obj
Data Types:

  1. 16-bit compiler will generate the machine code that is targeted to work for 16-bit microprocessor
  2. Highest bit is used to store the sign of the integer.
  3. Long int/ long(Atleast 4)
    1. Short int/short (atleast 2 bytes)
    2. Ints never bigger than longs
  4. If the constant value is small to be satisfied by int but we want more storage so we can have
    1. Int I = 23L.          //This will assign more space to it.
  5. Signed and unsigned:
    1. a.     Signed int i
    2. b.     Signed I; //Default is signed.
  6. Signed and unsigned int;
  7. Signed and unsigned char;
  8. Signed and unsigned float
  9. In case of signed if we assign a character that has int value greater than 127 then rollover happens and value from the other side gets assigned to it.
    1. When we attempted to store 128 in char then the negative value get stored in char\
    2. If we exceed range on positive side we end up on negative side and vice versa.
  10. Int has 2/4 bytes of memory.
  11. Long = 4
  12. Short = 2
  13. Float = 4
  14. Double = 8
  15. Char = 1
  16. Long double = 10 bytes
  17. Data types: Summary
    1. Signed int
    2. Unsigned int
    3. Short signed int
    4. Short unsigned int
    5. Long signed int
    6. Long unsigned int
    7. Signed char
    8. Unsigned char
    9. Float
    10. Double
    11. Long double
  18. The size of int, char, float is compiler dependent
  19. The negative numbers are stored in 2C format.

Storage Class:

  1. It specifies where the value of the variable should be stored.
    1. Memory or CPU registers.
    2. Storage class defines it.
  2. Types of storage classes:
    1. Auto
    2. Static
    3. Extern
    4. Register
  3. Storage class specifies:
    1. Location of variable
    2. Initial value
    3. Scope
    4. Life
  4. Auto:
    1. Location: Memory
    2. Initial value: Garbage if not assigned
    3. Scope: Local
    4. Life: Till the control remains in the block, where it is defined.
  5. Static:
    1. Location: Memory
    2. Initial value: Zero
    3. Scope: Local
    4. Life: Persists between function calls.
    5. Avoid it unless you absolutely needs them. They are stored in the memory and use up space even when they are  active.
    6. They get defined in the data segment. Die only when program execution comes to an end.
  6. Registers:
    1. Location: CPU Register
    2. Value: Garbage
    3. Scope: Local to the block
    4. Life: Till the control remain in block
    5. Same as auto only it is defined in the registers
  7. Extern:
    1. Location: Memory
    2. Value: Zero
    3. Scope: Global
    4. Life: Till the program execution comes to end.
    5. They are available in other files too where they are not declared
    6. Example:   Int main( { Extern int I  } int I =10;
  8. Static variable can be defined outside all the functions and it will be available to all functions. But it will not be available to other functions in other file.

No comments:

Post a Comment

NoSQL

This one is reviewed but I need to delete its copy from hubpages or somewhere NoSQL Data models: key-value  Aggregate model.  key or i...