C Programming and Computer Geeks

Search MY Blog

Sunday 14 July 2013

Arrays & Dynamic Memory Allocation - Basic Faq

1.How can I set an array's size at run time?  How can I avoid fixed-sized arrays?
ANS: The equivalence between arrays and pointers allows a pointer to malloc'ed memory to simulate an array quite effectively. After executing
               #include <stdlib.h>
               int *dynarry;
               dynarry = malloc(10 * sizeof(int));
(and if the call to malloc succeeds), you can reference dynarry[i] (for i from 0 to 9) almost as if dynarry were a conventional, statically-allocated array (int a[10]). The only difference is that sizeof will not give the size of the ``.

Friday 5 July 2013

C Faq - Part 3

1. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(void)
{
  int a=5;
  float b;
  printf("%d",sizeof(++a+b));
  printf(" %d",a);
  return 0;
}


Tuesday 2 July 2013

C Basic Faq


1. What is C language??
The C programing language is a standardized programing language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages. C is prized for its efficiency, and is the most popular programing language for writing system software, though it is also used for writing applications.

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

Search This Blog