General:
- ++ or -- cannot be used on enum value.
- sprintf could be used to convert an int or float to a string
- free() frees the memory during run time
- fflush() flushed all the streams and the specified streams.
- randomize(): returns a random number generator with a random value based on time.
- fprintf- Can be used to print the output to the screen.
- '\o' is called as NULL in AScii
- ftell() tells the current position in the file stream
- frewind() goes to the start of the file.
- 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.
- Hence, standard library is not a part of C package.
- fmod performs floating point divisions. Hence you cannot use % operator on the float.
- Types of linkages: Internal, External, and None
- By Default a real number is treated as double
- If we use extern as a qualifier then we should declare it outside.
- Any pointer size is 2 bytes. (only 16-bit offset)
- a. So, char *s1 = 2 bytes.
- b. So, char far *s2; = 4 bytes.
- c. So, char huge *s3; = 4 bytes.
- A far, huge pointer has two parts: a 16-bit segment value and a 16-bit offset value.
- 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).
- When an automatic structure is partially initialized remaining elements are initialized to 0(zero).
- When an automatic array is partially initialized, the remaining elements are initialized to 0
- Yes, In all the global variable declarations, you need to use the keyword extern. And it has only one definition
- In 16 bit compiler, the pointer size is always 2 bytes.
- In 32 bit compiler, the pointer size is always 4 bytes.
- sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes
- sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.
- sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.
- Recurrence relations are used to find the big Oh of the recursive functions
- Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.
- 16-bit compiler will generate the machine code that is targeted to work for 16-bit microprocessor
- Highest bit is used to store the sign of the integer.
- Long int/ long(Atleast 4)
- Short int/short (atleast 2 bytes)
- Ints never bigger than longs
- If the constant value is small to be satisfied by int but we want more storage so we can have
- a. Int I = 23L. //This will assign more space to it.
- Signed and unsigned:
- Signed int i
- Signed I; //Default is signed.
- Signed and unsigned int;
- Signed and unsigned char;
- Signed and unsigned float
- 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.
- When we attempted to store 128 in char then the negative value get stored in char\
- If we exceed range on positive side we end up on negative side and vice versa.
- Int has 2/4 bytes of memory.
- Long = 4 bytes of memory
- Short = 2 bytes of memory
- Float = 4 bytes of memory
- Double = 8 bytes of memory
- Char = 1 bytes of memory
- Long double = 10 bytes
- Data types: Summary
- Signed int
- Unsigned int
- Short signed int
- Short unsigned int
- Long signed int
- Long unsigned int
- Signed char
- Unsigned char
- Float
- Double
- Long double
- The size of int, char, float is compiler dependent
- The negative numbers are stored in 2C format.
- FILE - a structure containing the information about a file or text stream needed to perform input or output operations on it, including:
- a file descriptor, the current stream position,
- an end-of-file indicator,
- an error indicator,
- a pointer to the stream's buffer, if applicable
Functions:
- In functions there is no precedence
- main() can be called from some other functions.
- For ex: a() { main()}
- One function cannot be defined in another
- Each function perform some isolated task.
- 2 types of functions:
- Library - Same type of functions are grouped together
- They reside on the disk.
- Written by people, who write compilers
- User Defined
- The number, type, and order of formal and actual arguments should be same.
- They(Actual & Formal) are treated as different by the compiler.
- return; //It will return the garbage values
- return(10,20); //Not allowed
- Pass by value:
- When the formal arguments are passed to the actual arguments. Then the arguments are not passed. Only the photocopy is passed.
- Formal arguments and local variables are defined inside the stack.
- Standard Calling convention:
- Arguments are passed in the Right to Left order.
- func(int a, int b)
- func(1,2); => b = 2 && a = 1
- Stack is cleaned up by the called function: For ex:
- Main() { Func(); //This function cleans up the stack }
- If the return type is not specified then int is assumed by default.
- The address cannot be negative. Hence, we can’t have sign associated with it. Hence %u.
- **p: A pointer, which contains another pointer address, which in turn contain the address of either int/char/float.
- Address are always whole numbers. Hence pointers cannot have floating point numbers.
- Compilers use stack for normal and recursive function calls.
- Whenever, we make a recursive calls. The parameters and the return address get pushed to the stack
- If we don’t have a base condition for the function then soon the stack will overflow and runtime error: stack overflow will come.
- Whenever, we compile the code we get object file. .c to .obj
Data Types:
- 16-bit compiler will generate the machine code that is targeted to work for 16-bit microprocessor
- Highest bit is used to store the sign of the integer.
- Long int/ long(Atleast 4)
- Short int/short (atleast 2 bytes)
- Ints never bigger than longs
- If the constant value is small to be satisfied by int but we want more storage so we can have
- Int I = 23L. //This will assign more space to it.
- Signed and unsigned:
- a. Signed int i
- b. Signed I; //Default is signed.
- Signed and unsigned int;
- Signed and unsigned char;
- Signed and unsigned float
- 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.
- When we attempted to store 128 in char then the negative value get stored in char\
- If we exceed range on positive side we end up on negative side and vice versa.
- Int has 2/4 bytes of memory.
- Long = 4
- Short = 2
- Float = 4
- Double = 8
- Char = 1
- Long double = 10 bytes
- Data types: Summary
- Signed int
- Unsigned int
- Short signed int
- Short unsigned int
- Long signed int
- Long unsigned int
- Signed char
- Unsigned char
- Float
- Double
- Long double
- The size of int, char, float is compiler dependent
- The negative numbers are stored in 2C format.
Storage Class:
- It specifies where the value of the variable should be stored.
- Memory or CPU registers.
- Storage class defines it.
- Types of storage classes:
- Auto
- Static
- Extern
- Register
- Storage class specifies:
- Location of variable
- Initial value
- Scope
- Life
- Auto:
- Location: Memory
- Initial value: Garbage if not assigned
- Scope: Local
- Life: Till the control remains in the block, where it is defined.
- Static:
- Location: Memory
- Initial value: Zero
- Scope: Local
- Life: Persists between function calls.
- Avoid it unless you absolutely needs them. They are stored in the memory and use up space even when they are active.
- They get defined in the data segment. Die only when program execution comes to an end.
- Registers:
- Location: CPU Register
- Value: Garbage
- Scope: Local to the block
- Life: Till the control remain in block
- Same as auto only it is defined in the registers
- Extern:
- Location: Memory
- Value: Zero
- Scope: Global
- Life: Till the program execution comes to end.
- They are available in other files too where they are not declared
- Example: Int main( { Extern int I } int I =10;
- 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.