C Programming and Computer Geeks

Search MY Blog

Sunday, 23 June 2013

C Faq - Part 2

1. NULL POINTERS [CLICK FOR ANSWERS]

  1. What is this infamous null pointer, anyway?
  2. How do I "get" a null pointer in my programs?
  3. What is NULL and how is it #defined?
  4. How should NULL be #defined on a machine which uses a nonzero bit pattern as the internal representation of a null pointer?
  5. If NULL were defined as "((char *)0)," wouldn't that make function calls which pass an uncast NULL work?
  6. I use the preprocessor macro "#define Nullptr(type) (type *)0" to help me build null pointers of the correct type.
  7. Is the abbreviated pointer comparison "if(p)" to test for non-null pointers valid? What if the internal representation for null pointers is nonzero?
  8. If "NULL" and "0" are equivalent, which should I use?
  9. But wouldn't it be better to use NULL (rather than 0) in case the value of NULL changes, perhaps on a machine with nonzero null pointers?
  10. I'm confused. NULL is guaranteed to be 0, but the null pointer is not?
  11. Why is there so much confusion surrounding null pointers? Why do these questions come up so often?
  12. I'm still confused. I just can't understand all this null pointer stuff.
  13. Given all the confusion surrounding null pointers, wouldn't it be easier simply to require them to be represented internally by zeroes?
  14. Seriously, have any actual machines really used nonzero null pointers?
  15. What does a run-time "null pointer assignment" error mean?

Saturday, 22 June 2013

C Faq - Part 1


1) Write a program to check whether a string is palindrome/not, without using string header file?
2) Program for prime number or not?
3) Generate fibonacci series up to n?
4) Factorial of a number using recursion
5) Write a program for Leap year?
6) Write a program to print all the perfect numbers from 5 to 100?
7) Program for LCM(Lowest Common Multiple) and GCM(Greatest Common Divisor) ?
8) Swap without using third variable?
9) Repeated Digits in a given number?
10) Number of even and odd digits in a number?
11) Program for converting floatto Binary Display?
12) float (*test(char a))(int b,int c) Explain this declaration?
13) Write a Program to display of C code or C file...
14) find the number is power of two or not?
15) How to reverse the bits in an interger ?
16) Count the number of 1's in a integer
17) Program for what type of machine u r using?Big endian or Little Endian?
18) Reverse the string of an array without using another array.
19) Swap LSB & MSB of an integer
20) Convert one Endian to another
21) whether the particular bit is One or Zero?
22) find the size of structure without using sizeof operator
23) Convert Decimal to Binary
24) Convert decimal to Hexadecimal
25) Write your own String Copy function
26) OutPut  of the program ?
       printf("%s\n", argv[argc]);
27) Write a program, which should through a segmentation fault ?

Friday, 14 June 2013

Linux Commands

1.  Everything in Linux is a file including the hardware and even the directories.

2. # : Denotes the super(root) user

3.  $ : Denotes the normal user

4/root: Denotes the super user’s directory
/home: Denotes the normal user’s directory.

5.  Switching between Terminals
§  Ctrl + Alt + F1-F6: Console login
§  Ctrl + Alt + F7: GUI login
6.  The Magic Tab: Instead of typing the whole filename if the unique pattern for a particular file is given then the remaining characters need not be typed and can be obtained automatically using the Tab button.

7.   ~(Tilde): Denotes the current user’s home directory

Tuesday, 11 June 2013

Bitwise shift operators

How do the bitwise shift operators work?


The bitwise shift operators take two operands: the first is a quantity to be shifted, and the second specifies the number of bit positions by which the first operand is to be shifted. The direction of the shift operation is controlled by the operator used. Shift operators convert their operands to 32 or 64 bits and return a result of the same type as the left operator.
Shift Operators
OperatorUseDescription
<<op1 << op2Shifts bits of op1 left by distance op2; fills with 0 bits on the right side
>>op1 >> op2Shifts bits of op1 right by distance op2; fills with highest (sign) bit on the left side
>>>op1 >>> op2Shifts bits of op1 right by distance op2; fills with 0 bits on the left side

Monday, 10 June 2013

C Compilation Steps

C Compilation Steps


The above diagram shows the C Compilation steps.
STEP 1: Preprocessor
The main function of the C preprocessor is to remove comments from the source code and
interpret preprocessor directives which are given by the statements that begin with #. the preprocessor would strip the source of the comments contained
within the /*...*/ and would include the files assossiated with #include statement
and finally generates hello.i file

STEP 2:Compiler
Once the C preprocessor has stripped the source code of the comments and expanded the
preprocessor directives given by the lines that begin with # , the compiler translates the C
code into assembly language, which is a machine level code that contains instructions that
manipulate the memory and processor directly, in a layer beneath the operating system.
compiler is directly responsible for converting C syntax into this machine level code.
 And finally generates  hello.s 

STEP 3:Assembler
converts the machine-level instructions into binary code.
Assembler generates the objective file hello.o
The object file hello.o contains a binary version of the machine language

STEP 4:Linker/Link Editor
If a source file references library functions or functions defined in other source files the link editor combines these functions (with main()) to create an executable file. External Variable references resolved here also. 
means it will includes all the libraries,other Object files/Modules.

STEP 5: Loader
Makes use of binary format interpreter and process executable file header,it also determines the sizeof exe image.

coordinates with virtual memory subsystem and allocates Virtual memory address space required to load the program image.

Copies the exe image to virtual memory space allocated.

invokes process management sub system to process the registration of the exe.

Process management subsystem allocates a process control block(PCB) object and register a process

PCBs are linked up for CPU time from Scheduler.

A process once acquire CPU slice will start execution.


Saturday, 8 June 2013

Linux boot process

In the early days, bootstrapping a computer meant feeding a paper tape containing a boot program or manually loading a boot program using the front panel address/data/control switches. Today's computers are equipped with facilities to simplify the boot process, but that doesn't necessarily make it simple.
Let's start with a high-level view of Linux boot so you can see the entire landscape. Then we'll review what's going on at each of the individual steps. Source references along the way will help you navigate the kernel tree and dig in further.
Overview
Figure 1 gives you the 20,000-foot view.

Search This Blog