Assignment-2

CS101                                      Assignment-2                    2010-2011

 

PROGRAMMING IN C

 

DECLARATIONS AND INITIALIZATIONS

  1. What is the difference between char *a and char a[]?
  2. How can I declare an array with only one element and still access elements beyond the first element (in a valid fashion)?
  3. What's the difference between using a typedef or a #define for a user-defined type?
  4. Is char a[3] = "abc"; legal?
  5. What is the difference between enumeration variables and the preprocessor #defines?

 

VARIABLES AND DATA TYPES

  1. What is the difference between the declaration and the definition of a variable?
  2. Do Global variables start out as zero?
  3. Does C have boolean variable type?
  4. Where may variables be defined in C?
  5. To what does the term storage class refer? What are auto, static, extern, volatile, const classes?
  6. What does the typedef keyword do?
  7. What is the difference between constants defined through #define and the constant keyword?
  8. What are Trigraph characters?
  9. How are floating point numbers stored? Whats the IEEE format?
  10. When should the register modifier be used?
  11. When should a type cast be used?

 

EXPRESSIONS

  1. Whats short-circuiting in C expressions?
  2. Whats wrong with the expression a[i]=i++; ? Whats a sequence point?
  3. Does the ?: (ternary operator) return a lvalue? How can I assign a value to the output of the ternary operator?
  4. Is 5[array] the same as array[5]?
  5. What are #pragmas?
  6. What is the difference between if(0 == x) and if(x == 0)?
  7. Should we use goto or not?
  8. Is ++i really faster than i = i + 1?
  9. What do lvalue and rvalue mean?
  10. What does the term cast refer to? Why is it used?
  11. What is the difference between a statement and a block?
  12. Can comments be nested in C?
  13. What is type checking?
  14. Why can't you nest structure definitions?
  15. What is a forward reference?
  16. What is the difference between the & and && operators and the | and || operators?
  17. Is C case sensitive (ie: does C differentiate between upper and lower case letters)?
  18. Can goto be used to jump across functions?
  19. Whats wrong with #define myptr int *?
  20. What purpose do #if, #else, #elif, #endif, #ifdef, #ifndef serve?
  21. Can we use variables inside a switch statement? Can we use floating point numbers? Can we use expressions?
  22. What is more efficient? A switch() or an if() else()?
  23. What is the difference between a deep copy and a shallow copy?
  24. What is operator precedence?

 

ARRAYS AND POINTERS

  1. How to write functions which accept two-dimensional arrays when the width is not known before hand?
  2. If a is an array, is a++ valid?
  3. Is char a[3] = "abc"; legal? What does it mean?
  4. How can we find out the length of an array dynamically in C?
  5. What does *p++ do? Does it increment p or the value pointed by p?
  6. What is a NULL pointer? How is it different from an unitialized pointer? How is a NULL pointer defined?
  7. What is a null pointer assignment error?
  8. Does an array always get converted to a pointer? What is the difference between arr and &arr? How does one declare a pointer to an entire array?
  9. Is the cast to malloc() required at all?
  10. What does malloc() , calloc(), realloc(), free() do? What are the common problems with malloc()? Is there a way to find out how much memory a pointer was allocated?
  11. What's the difference between const char *p, char * const p and const char * const p?
  12. What is a void pointer? Why can't we perform arithmetic on a void * pointer?
  13. What do Segmentation fault, access violation, core dump and Bus error mean?
  14. What is the difference between an array of pointers and a pointer to an array?
  15. What is a memory leak?
  16. What are brk() and sbrk() used for? How are they different from malloc()?
  17. What is a dangling pointer? What are reference counters with respect to pointers?
  18. What do pointers contain?
  19. Is *(*(p+i)+j) is equivalent to p[i][j]? Is num[i] == i[num] == *(num + i) == *(i + num)?
  20. What operations are valid on pointers? When does one get the Illegal use of pointer in function error?
  21. What are near, far and huge pointers?
  22. What is the difference between malloc() and calloc()?
  23. Why is sizeof() an operator and not a function?
  24. What is an opaque pointer?
  25. What are the common causes of pointer bugs?

 

FUNCTIONS

  1. How to declare a pointer to a function?
  2. Does extern in a function declaration mean anything?
  3. How can I return multiple values from a function?
  4. Does C support function overloading?
  5. What is the purpose of a function prototype?
  6. What are inline functions?
  7. How to declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
  8. Can we declare a function that can return a pointer to a function of the same type?
  9. How can I write a function that takes a variable number of arguments? What are the limitations with this? What is vprintf()?
  10. With respect to function parameter passing, what is the difference between call-by-value and call-by-reference? Which method does C use?
  11. If I have the name of a function in the form of a string, how can I invoke that function?
  12. What does the error, invalid redeclaration of a function mean?
  13. How can I pass the variable argument list passed to one function to another function.
  14. How do I pass a variable number of function pointers to a variable argument (va_arg) function?
  15. Will C allow passing more or less arguments than required to a function.
  16. Whats the difference between gets() and fgets()? Whats the correct way to use fgets() when reading a file?
  17. How can I have a variable field width with printf?
  18. How can I specify a variable width in a scanf() format string?
  19. How can I convert numbers to strings (the opposite of atoi)?
  20. Why should one use strncpy() and not strcpy()? What are the problems with strncpy()?
  21. How does the function strtok() work?
  22. Why do we get the floating point formats not linked error?
  23. Why do some people put void cast before each call to printf()?
  24. What is assert() and when would I use it?
  25. What do memcpy(), memchr(), memcmp(), memset(), strdup(), strncat(),strcmp(), strncmp(), strcpy(), strncpy(), strlen(), strchr(), strchr(),strpbrk(), strspn(), strcspn(), strtok() do?
  26. What does alloca() do?
  27. Can you compare two strings like string1==string2? Why do we need strcmp()?
  28. What does printf() return?
  29. What do setjmp() and longjump() functions do?
  30. Whats the prototype of main()? Can main() return a structure?
  31. Is exit(status) equivalent to returning the same status from main()?
  32. Can main() be called recursively?
  33. How to print the arguments recieved by main()?

 

STRUCTURES, UNIONS, AND ENUMERATIONS

  1. Can structures be assigned to variables and passed to and from functions?
  2. Can we directly compare two structures using the == operator?
  3. Can we pass constant values to functions which accept structure arguments?
  4. How does one use fread() and fwrite()? Can we read/write structures to/from files?
  5. Why do structures get padded? Why does sizeof() return a larger size?
  6. Can we determine the offset of a field within a structure and directly access that element?
  7. What are bit fields in structures?
  8. What is a union? Where does one use unions? What are the limitations of unions?

 

PREPROCESSORS ( MACROS,HEADERS ETC. )

  1. How should we write a multi-statement macro?
  2. How can I write a macro which takes a variable number of arguments?
  3. What is the token pasting operator and stringizing operator in C?
  4. Define a macro called SQR which squares a number.
  5. What should go in header files? How to prevent a header file being included twice? Whats wrong with including more headers?
  6. Is there a limit on the number of characters in the name of a header file?
  7. Is it acceptable to declare/define a variable in a C header?

 

BIT FIDDLING

  1. Write a C program to count bits set in an integer?
  2. What purpose do the bitwise and, or, xor and the shift operators serve?
  3. How to reverse the bits in an interger?
  4. Check if the 20th bit of a 32 bit integer is on or off?
  5. How to reverse the odd bits of an integer?
  6. How would you count the number of bits set in a floating point number?

 

FILE OPERATIONS

  1. How do stat(), fstat(), vstat() work? How to check whether a file exists?
  2. How can I insert or delete a line (or record) in the middle of a file?
  3. How can I recover the file name using its file descriptor?
  4. How can I delete a file? How do I copy files? How can I read a directory in a C program?
  5. Whats the use of fopen(), fclose(), fprintf(), getc(), putc(), getw(), putw(), fscanf(), feof(), ftell(), fseek(), rewind(), fread(), fwrite(), fgets(), fputs(), freopen(), fflush(), ungetc()?
  6. How to check if a file is a binary file or an ascii file?

 

 

Ċ
Kapil Sharma,
Nov 13, 2011, 2:00 AM
Comments