Вы находитесь на странице: 1из 25

ANSWERS & HINTS TO THE

C-295

Compiled and written by

Somil Gupta
IT://20138026
MNNIT Allahabad

Formatted by -
@MNNIT : LNB Dipunj Gupta
CSE:// 20154061
MNNIT
A note for pointer dereferencing..... Remember when you write * with a variable that isn't dereferencable , it will give a
COMPILATION error saying the variable is not of type for unary *, its not a lvalue error...(Thing to remember)...
Compiler is particular about * operator and only allows variable with apt degree of dereferencing... not just pointer but
pointer of correct type required... Another point is that when we say *str, it means we wish to obtain the location of the
address stored in str.... and NOT its value...therefore char *str="somil" then *str would mean the memory location of the
first 's' and not the 's' itself.... this makes (*str)++ where str is non-const pointer....*10 is wrong... However, the compiler
checks the variable and its corresponding dereferencing and not the value stored in the pointer.... by typecasting, you
may store an arbitary value to a pointer which may not be allowed. *(char*)0 is allowed...Example 94 ques...
IMPORTANT:Until and unless you do not explicitly create a pointer, & of a defined pointer has the same value or
points to the same memory block but with different pointer type... So if a is address of a memory block..then &a will
have the same value although the type of pointer will change, from int * to int (*) [6].... so a and &a will have the same
value...although when stored in a diff types.. similarly, a and *a may point to the same address, even **a, until memory
not changed...
A pointer's type if matches with the type of memory, it jumps by 1 otherwise as per the corresponding type ... jumping is
based upon the size of the members it points to..
About BIT-FIELDS:... The bit-fields are assigned as per endianess... the bits are aligned one after the other if aligned....
the bit fields can have integral type datatypes only.... lies the significance of datatypes lies only with the availability of a
new chunk.... Otherwise they are all identical and have no difference...:0 with is error... but :x without name mean
padding...special :0 without name refers to alignment to the next chunk.... when varying datatypes... the chunk of the
largest size considered....

Regarding Switch case statement... if brackets put, it becomes a block and then break would mean breaking out of the
switch block but in case of no brackets only the adjoining case would be accepted and that too with a lines inside {}.

1. 100.Preprocessing.

2. to print % use %%.

3. There is a comment in between /*... */. bc is treated single token 'bc' and not as b,c separately. Although fun(k) is
parameterised there is no replacement as k is not defined. Comment /* has greater preference over all operators. Start
and end comments can be placed between tokens as well because comments are removed during precprocessing stage.

4. %nd reprsents width of integer including -ve sign. scanf prints no. of valid inputs while printf length of printed string

5. Any no. starting with 0 is treated as an octal. 0x as a hexa. if any invalid character then gcc gives comp. error. %i is
for all bases integer value, %d only for decimal, %o is for octal and %x is for hexa.

6. Precedence of relational over assignment... Remeber, fclose closes the file associated with the file pointer and also
flushes all the internal buffers associated. fclose may not turn file pointer ot NULL;

7. There are differences between memory allocations of static, non-static, local and global. Allocations are done
contiguously. # should only be associated with preprocessor directives. #INC can not be defined. Preprocessor
directives cannot be recursively expanded. Regarding const variable: levels from top to bottom are arranged from
varible farther to the variable...separated by stars..... to make any level constant just write const at that level.

8. Concatenation operator as a single token.

9. \ has the following funct.


a. Act as escape character, if does not recognize it only prints the letter(also applies to spaces).. Also comments
inside string literal do not work... in case \%d=%d=number
b. Act to prevent line breaks and ignores preceeding spaces....this can be done to join single token pieces in 2
different lines...This is a preprocessing step.... the tokens are joined together if possible... leaving different tokens in
different lines...
c. If found between % and recognized character, then all the spaces are ignored and the token %d taken as it is.
%\n==%<-|

*10. Function declaration can be given anywhere. In the declaration, since C does not promote function polymorphism,
therefore multiple names not allowed. Resolving and declaring are 2 different things. When declaring the compiler is
told about the function name and the number of arguments, so if only
function name to be given, give without any arguments ()<variable number> using void and int,int fixes. In resolving
during runtime, function calls can have variable number of arguments, adjusts accordingly.
Order of argument evaluation is undefined, although it mostly works from right to left.
http://stackoverflow.com/questions/367633/what-are-all-the-common-undefined-behaviours-that-a-c-programmer-
should-know-a

11. Memories in stack increased. Assigned one after the other. Heap undefined.

12. In this char pointer to hard coded string in terminal is added, which is readable only, so no changes allowd while in
char array changes permitted.

13. http://www.geeksforgeeks.org/interesting-facts-bitwise-operators-c/ Swap without using temporary variable.

14. In scanf putting %*d skips the character. But in printf for %*d the format string expects two arguments: one for *
which is variable width and the other for integer value corresponding to %d.. same applies for %*.*f

15. http://www.tutorialspoint.com/cprogramming/c_bit_fields.htm Bit fields used... Remember, size of does not work on
bit fields...

16. Here #DEFINE without any replacement leaves nothing. Such null macros are of use only for decision making. #IF
AND #IFNDEF etc.

17. shift operators are left-right associative. So 2 in 1st and 0 in 2nd.. divide by 2^2.

18. All global variables and stack and static data are allocated duirng compile time in DS, BSS. while all the function
calls and local variables and dynamic allocation is made during runtime. Therefore when the global variables are made
they must be initialiozed with a constant (string literal too). Plus there is a header named malloc.h also. If hard coded
string changed it causes seg. fault. Also, {'a,'r}kind initialization is cannot be done to char pointers. If exceeds the
number in case of char str[n], only n numbers kept. (undefined result)

19. [] has higher precedence over -- also num[i]==i[num] so --num[i].. Now solve. Remember ++i++-l vaue required...

20. Same as previous ques... typecasting in warning. In C++ not allowed.

21. Precedence of assignment<ternary<logical<relational also associavity ternary RL , solve ternary recursively inside
to out, also remember the concept of short circuit. Here 10 && x>y would act as the condition.

22. In unary operators , associativity RL. &a[0] is const char* to int ... in expressions a assumes special role as &a[0].
Exceptions are size of where size of whole array and &arr is a pointer to whole array and not to 0th element ... no
change possible. Size of pointer is //architecture dependent and datatypes is compiler dependent//.Ternary operators are
evaluated recursively from innermost to outer.

23. Easy ques. fun() has no argc or args

24. Concatenation of strings.


25. pointer starts from the pointer + no. Also no.+pointer=pointer+no. , escape are treated as single character.in case if
%d or %f used first string is truncated then rep;acements occur. in case of \k it converts to k

26. Firstly unsigned is implictly taken as int.. There is always an ambiguity between ++ and + or between - and -- ,
compiler has made it a point that until isolated + or - not found, all + and - in adjacency are treated as ++ / -- and
therefore with more than two in adjacency, that may give lvalue error. however if in spaces, they are treated as unary +
and -... 2^32+-ve no. gives unsigned integer. also that +++ would be treated as ++ and then operator +. ++>bin +>unary
+....

27. Enum is similar to struct that caters to the relationship of class-objects. Enum is a user-defined structure whose
variables are basically like any other int variable, only that its literals can be user defined and correspond to the number
given... comma operator works as usuaal.

28.Read these links...http://www.programmingsimplified.com/c/source-code/assert


http://www.cplusplus.com/reference/cassert/assert/ http://stackoverflow.com/questions/1081409/why-should-i-use-
asserts http://stackoverflow.com/questions/1081409/why-should-i-use-asserts

29.Structure is also a user defined type... nothing extraordinary.

#30.{} denote a scope... Also what is deduced here is that first program is checked for validity of all tokens and
syntactical errors and only then the undefined reference in symbol table are checked... Linking is always after
compiling... basically , references are resolved via internal linking which is always after the compilation process... use
gcc -c to see the difference. However if you put void in c() and int in C(),the code would work.... Indeed nested
functions possible...http://stackoverflow.com/questions/8090975/function-definition-inside-another-function-definition-
is-it-valid , http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

31. void returned cannot be received as there is no typecast for void. This is not in case of void pointer. Extern keyword
can be used to make a local variable global ... i.e. to refer to the variable written inside a function. Basically, extern
allows it to be used in all files.

32. Nothing so important... If size(long long int)=8 what will be of sizeof(i==100000)=4

33. Preprocessor statements are case insensititve...nothing else...

34. Similar to q3.

35. static string shall be allocated in Data Segment. Mutable. Rest precedence []>++,etc.

36. Structure : Here the array a is actually an array of struct s's. Everything else is normal. Some points to remember-
a. When initializing a structure or multi-D array, not neccessary that the array is intialized as {{....},{...}}, but
because of the fact that these structures are stored linearly in memory(rowwise), you may initialize sequentially {.....} .
However then you cannot miss any initialization, which is possible in case of {{},{}}.
b. Structure is always taken in multiple chunks of memory, therefore a structure of 3 chars will have to have 4 in
sizeof.
c. bitfields always integers. They can be taken alongwith other data types. by default signed.
d. Since template of structure has no memory allocation in defintion therefore initialization whether constant,
variable or dynamic is not allowed.
e. const is allowed in structure. About consts const int* cons (first const for constant value and second const for
constant pointer. However indirectly these values can be changed. Eg. k=5; const int *p=&k; now if int **g=&p;
**g=10; will change value of k although made constant via p.

37. Concept of bit fields as usual. For signed bits take 2's complement. Also in a struct all bit fields must have some
type.. For concepts of struct-
a. structs can be defined without template name. But such templates are trivial as their instances can only be used
during their declaration... In cases with no template name, definition=declaration.Static structures are those whose
memory is allocated in Data or Bss.

38. In case of str[] sizeof also includes size of null and in case of char* only size of pointer is returned. Result is
undefined as there is memory overflow in string. Space insufficient.. Seg. Fault may occur either in this case or in case
of overlap of strings in strcat.

39. File related ques.: Read C in depth files...Every time we use fopen with a different pointer, a buffer is associated
with it to which data is flown only when fclose occurs. However in case of fopen with w it cleans the file, a adds
newline. Different calls with same mode are possible. The file position is associated with FILE structure which is
intially intitialized to 0. Other modes are also allowed.

40. Strings end with null plus when interchanging index has not been kept into consideration.

41. Nothing extraordinary... only first one taken...

42. '-' - '-' shall give 0 (ASCII values) which gives 0+"hard coded string"... a pointer to the first character is sent. the
char* is not a constant but the string to which it is pointing is .. therefore actual string printed.

43. Case of type promotion...:UL>L... unsigned always greater than signeds.. refer to c in depth...for type conversion
procedure... since -1UL=2^32-1 >1L so first one.

44. Switch cases can have calculation even in switch labels... All types of int including long long is allowed... it forms
symbol table to match... calculations at compile time so no variables allowed... case lables can be after default too... two
lables cannot be the same....

45. statements like scanf and printf can be written in for and while constructs, follow the sequence in which for
statements are executed understand the process...feof finds whether the current position pointer is EOF or not... similar
is perror... Now each stream or pointer is associated with a buffer which is flushed either on fclose or on SUCCESSFUL
termination but not on interrupt signals.... problem here is that EOF cannot be typed so on ^z or ^c it ends the program
... buffer unable to be added, hence no addition... Try adding fflush(fp) inside loop... characters will be there in file...
remember there is no diff. in c.txt or c.out... or check for a to be ; for termination... then the proceeding lines are added
to file and printed... read more of buffers in c in depth..

46. only a trick..otherwise call by refernece...

47. Undef is required to undefine any definition.... nothing extraordinary on replacement extra () would cause
error....scanf returns no. of valid inputs or values allocated.. also chec that in scanf & not placed..therefore seg. fault...

48.firstly here enum is just a declaration and with no variables. p.10 is invalid because union p must have a memory
location after . but only declaration renders it useless.. Enum however has an advantage that its literals are mentioned in
symbol table and replaced during compile time therefore any redeclaration is not allowed... enum constant need not to
be always associated with enum variables but may anywhere replace constant integral values in the scope ... act like
preprocessors. Union uses the same memory with all the variables inside it.

49. firstly gets returns char* pointer otherwise null if no string... **puts returns sizeof the string including null
character... putchar returns the input character in integer... getchar returns the character, comma returns the value of the
last expression although all evaluated...use these to solve...

50. Preprocessing... only keep in mind that brackets around x and y are important... if any expression eg 2,3 that mind
hamper the ternary operator comes, then also brackets shall be dealing them effectively.

51. enum theory as in 48, fall through will occur so take care... sizeof will create error because it can either take in
variables, constants or datatypes. SO it will say try undeclared. sizeof() works on i++ or assignment too but no
increment occurs. No declaration occurs inside it. Also malloc allocation also does not occur inside... sizeof is
COMPILE TIME OPERATOR. Only variable length arrays are exception.

52. preprocessing replaces scanf in printf .... keywords excuse as error is irrelevant because it happens before
compilation... just replace and follow the printf thing.

53. printf returns no. of printed characters including escape, remember first the arguments evaluated then the original
control string. 390 first then 3 then enter then 2.

54. In enum, the sequence starts from 0 until explicitly mentioned after which it follows the same sequence hence two
literals can have the same value. therefore 0+0=0

55. Assignment precedence form left to right.. right gives ffff0000 ... middle one is an expression... so lvalue error....
Had we stored and followed ... middle expression would have given 0.

56. comma operators result is always the last exp., which here after p=1 gives p=0, therefore no looping and only
KIRAN printed.

57.Register value in order to be easily accessible are stored cache and not in RAM, although it depends on availability
and is only a request. However adress cannot be accessed because it is out of memory.. so no & or * is allowed... gives
error...

58. Remember in printf and scanf when any other datatype espically %d or %f for float or int, then a undefined value is
printed... upon representation it may change. Plus one more point that change of scope does not affect initialiation but
declaration. Behaviour is undefined.

59.strlen finds length, firstly it will give seg. fault because in strlen *cat++ would mean cat+=1 followed by its
dereferencing i.e. *c which will give seg. fault as it goes into kernal space. if we remove * and apply string.h, strlen
finds length till null so 3 at start and follow while to get 1 2 3.

60.http://stackoverflow.com/questions/13216423/error-pasting-and-red-does-not-give-a-valid-preprocessing-token ...
Token pasting operator has the task of pasting the two sent parameters and combine them into a valid preprocessing
token... the sent paramenters must also be seperated by a non-paramenter character so that the lexical analyser can
identify both... else it gives error..Read this .... http://tigcc.ticalc.org/doc/cpp.html.... since string literal is one of the
tokens preprocessor defines... and string literals are restricted....By a single token we mean preprocessing token... read
the article... mostly preprocessing literals and numbers can only be pasted. Read concatenation... Also comments are
whitespaced.

61.sizeof in case of bitfields even in union is 4... also sizeof cannot be applied to bitfield...signed:5 is possible without a
variable reference, it means in struct to leave some bits,....since a union, the defined bit fields will not be continuous but
one will replace the other. No zero width bit field can be defined... neither can bit be greater than 32. Size of structure is
highly unpredictable... with char it gives one but char and int give 8. Size with signed:30 is also unpredictable. Called an
undefined behaviour, owing to padding.

62.Union has the size of the largest element in it... in this case the structure. Structure's size would be 8 because of the
padding... mostly a simple observation is that integral values are always assigned the 4th byte address. Structure inside
may have no variable defined, eg. only declaration, this declaration may be valid outside the union. It will make the
structure inside this union worthless, although no memory allocated for the structure. A variable of this structure may be
defined outside.Union's are also self refer ntial;

63. Since the condition gives true, it does not go into el...y]

64. Normal assignment and short circuit question... &&> ||


65. Structures http://www.geeksforgeeks.org/little-and-big-endian-mystery/ Allocation in structure occurs one after the
other... i sequence of declaration ... padding is done in between the elements...

66.Unsigned int typecasted... Unsigned have no use except as integers... add 256 to convert to unsigned..

67. Switch case is implemented via symbol table during compile time. ... therefore case labels cannot be variables...
enums constants and all are allowed. since the switch directly takes the execution to the label, or end in case of no label,
irrespective of the intermediate statements. IN c++, constant pointers are replaced at compile time in the symbol table
itself, therefore they can be used as labels. Once the label is reached, the following statements will be executed until
break or end of switch. Therefore this will undergo the looping process. Once the jump has occured, the labels become
worthless and the statements are executed normally... To understand, if you know about goto and its labels, switch can
be the go to statement and cases its labels... default can also be placed anywhere inside switch. Breaks can only be
within loop or switch while continue can only be within loop. here it will work because the continue will have a loop
around it... this even works when a continue is within switch which itself is within a loop. Break however would look
for the nearest switch or loop break.

68. Normal strings ques.. remember puts converts \0 to \n so in example even if c is allocated 12 the return value of
puts(c) will be 6. + puts adds a new line at the end. Deprecation fn means a function that may cause unhealthy results
and should be avoided. read this ,... buffer overflow may occur in gets...
http://stackoverflow.com/questions/2843073/warninggets-function-is-dangerous....When we have a dangling pointer,
the buffer input is not spilled to any memory location and therefore lost.
http://stackoverflow.com/questions/26602608/whats-the-difference-between-gets-and-scanf... Therefore use fgets....

69.Ques explains the difference between comma operator and function arguments. Inside prototype definition, function
arguments separator ',' holds greater precedence than comma operation therefore if brackets removed, it would it treated
as arguments and since multiple arguments do not crea. When inside brackets comma operator holds greater precendece
since it turns as an expression therefore 100.

70.Question of bitwise and precedence... previously a compilation error because ~ is an bitwise complement operator
therefore ~= is no operator... On correcting that, << >> have associativity from LR so 0 inside then follow as given,...
first 0 then -1 then 0 then -1 and lastly 0.

71. these are predefined macro variables .... line prints the line of the file where it is written which is not the no. of
statement... __FILE__ is the source file name.

72.http://www.codeitive.com/0JxVWPXVeP/getting-conflicting-types-for-function-in-c-why.html.... Then comes the


error of undeclared function....
Apt explanation:http://computer-programming-forum.com/47-c-language/d0e9c29091232971.htm
When a undeclared function is called, the compiler creates a declaration on its own with variable no. of arguments and
int return type... therefore if function two(2,3,4)=== int two(); If the defintion of this function has any other return
type... it gives conflicting type error... with int it works fine but with void it gives only a warning...In this case it allows
a recieving variable with a warning and no error.. because at first it was expecting an int... therefore undefined
behaviour... Now the value obtained is in a way undefined....
The error with float at first... is that of default promotion....http://gavinsmith87.blogspot.in/2012/04/notes-on-c-default-
argument-promotions.html...Read prakhar's notes...Also, scope of a declaration remains only until the point of the end of
the file, hence cannot be
made to match a definititon in a diff. file, in this case one may safely assume that the values

73. when local variables are assigned, the memories are alloted sequentially... remember the addresses of these pointers
will be sequential and not their values....p1+4//in a way adds 16 bytes... remember the basic fact about pointers 1+p and
p+1 is same .. + and - are binary operators .... the operands can only be int or pointers... and if two pointers are being
subtracted...they must be of the same type.... when stored.... the address is typecasted... remember also that p3-p1=1 and
p1-p3=-1... Stack increases with address... (grows down)
74. Representation of a is int (*) [3]... of pointer to an array of (*)[2][3] or 1st element of 3D arrays.... Go through the
pointer representation..... when *(a+j) convert to a[j] ... and then **a is *(*(a+0)+0)...... a[0][0]... C complicated
declaration with function pointers...

75. Firstly argv is array to char* ..... atoi is function that takes in char* and gives int.... argv are in the stack area and not
in the text segment so can be changed... given definite memory.... as function arguments to main...

76. Local variables get leaked after function ends... values not destroyed but may be corrupted so you really cannot
really be sure.... Mostly the integral values may be retievable but the string may not be retrievable.... So answer of string
is undefined... This is called pointer persistence...However if it was local static variable, variable could have have been
obtained....

77. "Called object is not a function or function pointer"-because in the local scope
http://stackoverflow.com/questions/12760301/what-does-printf-returns-if-not-called-as-function
Function name denotes an address...
size_t (*my_printf)(const char *, ...) = printf;
my_printf("This actually called printf!\n");

printf("my_printf: %p\n", (void *)my_printf);


printf("original printf: %p\n", (void *)printf);

Some observations:
1. Functions and objects cannot be redeclared in the same scope(i.e. no two external or internal of the same name).
2. Local variable always overshadows a global variable of the same name.
3. Even local function and global variable can have the same name.
4. Local variable can be defined after global variable... in that manner until local variable not defined in the function,
global variables prevail...
5. Take the two as an entity and then use the same concepts of local and global.....

78.sprintf and sscanf work similar to printf and scanf output is no. of characters printed and the valid inputs.....
http://stackoverflow.com/questions/5406935/reading-a-string-with-scanf... Read this important post... &s and s has no
diff.

79.Error because :0 not possible in variables,Unsigned means that when copied... the highest priority bit does not
extend... but in signed bits, sign extend takes place, in this case no. stored.... size will be 4 but if f7 was not there then
8....##Bitfield possible in union also... In that case fields overlap ... padding elements have no signifance and neither :0...
So all of only the size ...

80. Explanation of how SCANF works..... the control string is traversed character by character and the buffer associated
with scanf is used to satisfy the input controlled by the control string.... The buffer does not flush between scanf calls
thus the buffer remains as it is.... when it encounters a default delimiter (\n and ' ') it keeps popping 0 or more of its trail
until a non-delimiter character arrives... %d,%f,etc... first keep popping out the default delims and extract the valid chars
until end of buffer(it waits until control string over), invalid char or def. delim. ... As for a fixed char, when there is no
space or something... it must be exactly replaced by the character i.e. when pointer arrives on the fixed char in control
string, the buffer must also contain that char, in the same frequency as given,,, if not, the entire scanf command fails and
that scanf control string no more checks moves forward for entering,,, all other remaining input variables are garbaged,
although buffer remains intact for the subsequent scanf calls....Exception: %c takes in delimiters as well so %c%c in
case of a g will give a and space while %c %c will give a and g..... ' ' will take in all delimiters....gets takes in \n and
replaces by \0 so space is also popped....%6c is writing 6 times %c six times and store contiguously over the memory
offered to it...... It is not equal to %ns.. because here if input <n it takes it as it is and does not wait for the input...
because it is after taking the string and then taking the desired no. .... This is because it is a single char...
81. Simple ques... only bracket operator working to be kept in mind....

82.Firstly, there is no declaration before call so there is no way the compiler may know whether the function is void or
not ... as in q72 it takes default definition as int abc() : so only gives a warning(However it is only with void, with all
other non-voids it gives error).. A function void with a value returned gives only a warning, however that value if
received is not the same as that value is not stored in return register....

http://stackoverflow.com/questions/1610030/why-can-you-return-from-a-non-void-function-without-returning-a-value-
without-pr .... Returning no value from a non-void function gives a warning because c and c++ are flexible in their
approach to functions... they say that some function not always require to return a value...or some conditions wish to
return and others do not....However the return is undefined... usually it is the last expression stored in eax register..... last
expression.... Another reason says it is not possible to check every code path...

83. Only a single replacement

84. Similar to sizeof operation... no. of 4's in between

85. Concept to remember : expansion of a macro whose arguments are themselves macros occurs in the following
manner-
Set A: Non- stringlizing and Non-token pasting operator
Set B: complement of set A
When you encounter a Set A, then first it expands the arguments completely(such that later it does not need to expand),
e.g. xcat(cat(3,4)3,3) will give cat(3,4)33->xcat(34 3,3)->cat(34 3,3)->34 33... If in a token that has already been pasted,
another token pasting operation of different
FOR SET B::::
first it expands itself incase if it has not been encountred in any of the previous calls....and then it tranfers the call to its
arguments disabling itself for the subsequent calls....however has has been disabled does not effect the previous
calls............

when solving such macros take the call as a parent and its arguments as its children....what has been disabled in one
child does not effect the other...incase of set A because it first goes to its children and then comes back to its parent
disabling is of no use...incase of set B if the operation occurs in a way both the children a concatenated together if the
conc. result forms a new token altogth.
EX ::
cat(a,cat1(acat1(2,3),3));
In this case acat is a new macro formed which if used later in disabled but the original cat1 which was an arg. to cat
remains enabled..however iif it was cat(cat1(acat....),a); in this case even after comb. both are diffrent tokens becoz of
unsuccessful pasting,so although it will give a preproccesing error it will expand further and give the final result as
expected with a attached at the end withut spaces.
If in a token that has already been pasted another token pasting occurs previous token breaks with a space
EX:::
cat(cat1(x,y),a)) in this case it forms xy a
if on combination the new macro formed does not exist it stil goes into its argument and expands them completlely and
the behavious is similar to that which is disabled.....
EX::
#define foo a,b
#define bar(x) lose(x)

bar(foo)....it expands as bar(a,b)->because we go to arguments because of set A.After completly expanding arg. bar(a,b)
gives no error because once te arg are expanded the parent macro has no regard for their children,So it continues its
expansion to lose(a,b) which expects a signal arg and gives an error.
In stringlizing , the string is formed, and nothing expands inside string...
86.

SYNTAX::::::: #define [identifier]definition


#definepreprocessing macros BOOM"Act"
the first arg of define should always be identifer excep. is parameterrised macros.
#define BOOM(a,b) ...
and u use BOOM(a) ....Incase if in the scope of a para. macro u use the same macro name but with diff no. of args. the
preprocessror throws error.Incase if the macro call has no args. implicitly 1 argument is send i.e BOOM(void) where
void is one arg.
EX::::
#define BOOM(a) a+b
BOOM()
error:: here it will be replaces by +b
.....For mentioning a string in preprocessors both single and double quotes are used in a def. or anywhere in the
preprocessing directives....Incase if in this def. the quotes are not ended them the entire def. from the begg. of quote till
the end of the line is considered a string and not replacement occurs.
#undef :: requires a identifier only and if multiple identifer is given only 1st is undefined and if the iden. is not present
then warnig is given ie it is just a request......
.....Include :: Nested includes work ...for eg. in the file stdlib.h there is another header file egs features.h... but there
should be no looping of the nested includes files exmple:: if a.h includes b.h and b.h includes c.h then c.h shud not
include a.h or b.h....

Conditional Compilations::
#if,#elif : syntax #if [constant expression] here a=q gives error because assingment reffers to memory, but at
prprocessing there is no memory involved.hence we get error.
only arithematic logical relational types operators can be used becoz the amount to some value.....There can be all
operators which are not related to memory...a++ doesent wrok ....the valid operands that are allowed are identifiers and
constants...if they are defined then then there respective values are exchanged after final replacement,,,(eg buffsize
tablesize example) if the are not defined then default value of tht identifier is zero....
Case::
#define a
if will be replaced by void in the xp..if the new expression formed is valid then corresponding value wil be obtained else
error will be thrown
a+b tranforms to +b (valid)
a*b tranforms to *b(non valid)
*******IMP:: the const exp should not conatin enum constants , sizeof operator , cast operator or variables.
#ifdef #ifndef : similar to as #undef
One more thing to remember that if in the scope of a parametrized macro, if we use ifdef then it gives yes but if used in
expression without parameters, it turns into an undefined variable with value 0, even though a parameterized macro of
same name exists....
preproessing removes comments with a single space.....

87. main function has no declaration and its function acts as a declaration.. in that sense it can take in any arguments, the
initital values will always be int, char*, called by OS. typecasting only occurs during actual arguements stack
making.We can never pass like {d24,342,324} but rather pointers to memory assigned in stack...

88. Function stack is first filled and when popped then evaluated.... Since pushed from left to right,, it is in a way
evaluated from right to left.... In such cases when the arguments are dependent on the values of previous arguments e.g.
i++, --i such expressions dependent on the priority of popping or evaluation and storage... it may be possible that the
storage of value of i occurs after the next element has been popped hence giving bad results, here maybe because of
derefencing this time is in a way covered up, hence giving accurate results.... However such behaviours may devour
unexpected results....
89. Same results as expected... about command line arguments... Research done in 87...

90. The overflow of unsigned int.. beyong 0 turns to -ve +2^32....

91. % and division by 0 gives floating point error(core dumped)... % is not allowed in floats and give error.... similarly
1/0 will give error but 1.0/0 will give a value which is INF... as it is a part of double... but not int.

92. l value error.... in c and c++ both... remember c++, comma operator gives l value...

93. Firstly the concept of scope is here.. when local overpowers global hides... so value returned is different, secondly
just like struct it is important that when a function pointer is to be called, its declaration must exist else an error...(in
function calls we leave but in name we cannot leave out.. A name of a function when used in any expression or respect
bascially represents the memory address of function and so its pointer is similar to writing declaration itself. Take
analogy with arrays... Once a particular declaration is mentioned, rules of previous calls and fun... take place so all
techiques of dealing with these in c and c++ are similar to how these functions would normally have been used used at
the place mentioned... As function local variable, function pointer names are local variables and need not to have the
same name..not even when mentioned as int fun()... because that implicitly is a local pointer to function... Similar rules
apply...

94. num is stored during compile time in data segment... So replacable... now remember the precedence of ++ and * and
the note at the top about dereferencing...The arguments evaluated from left to right... as we had seen that during
dereferencing and refering to the memory... there is no error because in all cases ++ occurs before * so ++ gets time to
finish up... (*(p--))-- p-- would give the value of the address of 1 which variable p stores and then decrement by 1... This
address is valid so when dereferenced it gives the memory location of this as address.. on which -- operation occurs...

95. signed in unsigned== 2^32-(no. if neg)...

96. Compliation error firstly because when replaced the void variable in a way gives int inside parameter which is
wrong...on removing that it gives block scope concept.... nothing unusual.

97. Pointer to functions:


1. The name of a function basically represents the address of the function i.e. basically name of the function is like a
constant pointer to a function whose linkage cannot be changed, therefore on writing function name inside printf it gives
the address... but if you try to equate the 2, i.e. fun1=fun2,had it been function pointer, it would have been possible...but
here it gives lvalue error...What it is exactly we do not know...
2. int (ptr[3])(); is not possible as it will error saying array of functions not allowed...this is to prevent use of direct
memory of text segment.
3. If you wish to use typedef int (*)(int,int) def; error, it is equivalent to using typedef of function pointer with variable
func.. so right way is int (*func)(int,int) this is good where we need to return the function pointer...compilcated def.
would be int (*fun(float))(int,int)...
4. Remember *abc where abc is a function is also allowed... (*fp)(), fp(), fun() all are allowd... *fp() will be error
because () has greter precednece so it will first call and then * but in compilation it will be an error as no unary....
In the ques... there is simply an array of pointer to functions and then all are called as variables...

98. local static data has scope inside function and memory in data segment therefore it retains value between function
calls... main is recursively called... In function definition () also denotes variable argument list and when called
recursively with different arguments it gives no error...recursive will find prototype earlier so error if mismatch....

99.Just follow how it is written ... when stored in int it is typecasted and then printed... remember when typecasting
occurs as in assignments... then value changes but when printed... only the memory is interpreted as per control
character.. remember this fact...

100. An amalgumation of two undefined behaviours-1. if you separate i---i and i+++i this behaviour is undefined,
because although associativity is fixed in order, the order of evaluation of operands is not fixed... In some it goes from
left-to right and from some right to left... Second, when the two opearnds are combined together in printf(), althought
the evaluation is from right to left, the error in stack filling and value increment at memory may have different times
which gives unexpected error.
---------------
FINAL RESULT FOR PADDING: The memory allocation or the delieverance of chunks will always be in the largest
datatype of the entire struct, or union... in case if a struct may contain another, struct, union,etc... then the constituting
datatypes will be considered.... allocation will always be in the highest datatype....
In printf and scanf then first arguemnt is always an expression yielding string....even a string variable can be given.

Floating operation is not allowed in preprocessing expressions, it gives errors....


Return carriage overwrites but to see that \n must be put....R

Whichever pointer type has (*) in its type, when written as return type must have function prototype along with * inside
brackets and if intitalized with an identifier as in typedef ... must have it inside () too... Read compilcated declarations...
-----------------------

101.. Undefined behaviour 0 and 2 if sepearately, <<= is assigment and not


shift...http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-
points,,,http://en.wikipedia.org/wiki/Sequence_point Every source says all arithmetic operations on the same vairable
are kind of undefined behaviours....

102.macro replaced as it is.... so 60

103. predefined concept... nothing new...

104.comments normally are removed and replaced with space during preprocessing... if they interfere with a single
token as a/* */b. then the space would separate tokens...a ##b does not create error because of space.... rather joins the
two...

105. Shortcircuiting concept of && and ||, here in ques first part is evaluated and then it goes to second part because first
part is ffalse.... also remember, whenever problem in assessing expression, may convert it into postfix...

106.gcd ques... nothing new

107.constant value cannot be changed.... however if we wish to change in c, use indirect pointer conversion method...
not possible in c++;

108.remember the size is 32 so ffff0000 and not 0000... plys + with spaces treated as unary....or binary... a++a will give
error while a + + a will not...

109.conditional treat like if else and evaluated accordingly..

110.The question here is finding the - operation answer on the two pointers... Although here it comes out to be 6... the
point to be learnt here is that &a[7] is converted implictitly converted by compiler to *(a+7) and with &* are cancelled
and the memory is neither referenced not accessed... therefore there will never be error regardess of the array size...eg.
a[23424324234]-a[1] will not give seg. fault...

111. c allows with warning, conversion...however if in the function the variable would have been double deref.. it would
have been error... Now this is a question of local variable... name was passed and not &name so when received... the
value was lost and in original function it remained unchanged... remember that values are stored and stored in local
variables.. so beware..

112. assignment inside if..... in int a=12,2 is an error..., acts as separator..


113. simple calculations,... .2f does round off. also that y/3 in single expression is evaluated as int and then converted to
flaot...

114.Go smoothly...functions on returning a value of a diff. datatype first typecast it ..... values will be stored as per
indexes...

115.static variables have memory in the data segment which is preserved between function calls.... scope only wihin that
function... however added to symbol table. Also in function defintition () means void and not variable no. of
arguments... So error if prototype had int and here it was ()...

116. In both cases 3 is produced, then break through occurs in switch case.... any case can be anywhere..even default
can be written on the top

117. escape characters counted as single characters... size of as per the size of array.. if not given it includes \0 too..here
7... strlen works till \0 so 2 here... Inside while the break works with the nearest hence switch..

118. remember ternary>assignment>comma... last expression of comma evaluated... also when 0 starting nos. are octal..
when when compared decimal with octal, octal converted..

119. Here although structure is allocated correctly...size will be system defined..here 8... but because value of a is stored
in char * when it is dereferenced for the priitng, kernal space is unreferencable hence not allowed...

120. when intialized via initializers, you have to mention the column nos. and subsequent indexes, else error...
exceeding intializers allowed but those are not considered, it forcibly takes it only as much as specified, and leaves out
the rest... e.g. char a[][3]={"hello","world"} would give in memory helwor and then garbage memory....
char (*a[])[7]={"world","hello"};
char b[][7]={"ab","as"};
Analyzing the two although the two represent the same thing one is an array of pointers to characters. while the other is
a 2d array withcontinuous representation..
printf("\n%d %d\n",*b-*(b+1),*a-*(a+1)); will give 7 and 177712321 ...
So as major rule, in arr[][] basically stack memory is allocated for all elements in the b element, and in a, only memory
is allocated for the pointers in stack that point to the memories of strings in the text segment.. therefore although the
defintion is same, the two are very different... Also when we do * we basically change the type of pointer which
although may be having the same memory location but will traverse with different jumps=size of the memory they
point..Since this deals with strings that pass memories therefore memory is passed..
Regarding role of initializers, when mentioned with subscript type... it creates memory and stores it in stack.... as per the
subscripts.... in the intializers.. the elements are filled as per the brackets in the intializer and the type of memory...
Basic type of initializer is to store the values given to it...
struct an
{
char b;
int a[];
}and={'c',{34,233,2333222}}; an example of flexible arrays.. if a[] had been before b it would have been an error.. and
if int*a was there ... then again 34 was there....

121. In sprintf, similar to printf returns the replaced final string with all the printable characters ..... does not include
null, (length and not size)..

122. Nothing unexpected..

123.scanf %s has space as delimiter while printf does not... all pointers have buffers associated to work on the same file
and see the results one of the pointers must be closed or flushed.. if not nothing would be obtained... printing and
reading with printf and scanf may use the same variable for different arguements... there exists a sequence point
between their processing because their execution depends on control string... Therefore world.

124.Nothing special

125. firstly else and if must have some statement...strlen() is o(n)... infinite because of unincremented i

126.l value error... otherwise the same.. &array gives memory of array while array gives memory of 1st ele...%#x means
give hexa with )x when %X means all letters in capital...

127.precedence of operators... assciativity in case of = and others...

128.remember precednece and associativity... Everything upon that... - same as ++..

129. Expands to main()


{
int x=1, y=2;
printf("%d",(x++<y)? y:x++), printf("%d",x), printf("%d",y);
printf("%d",(x++<y)? y:x++), printf("%d",x), printf("%d",y);
}
Just keep in mind, the concept that in ternary operators every condition or statement has sequence point at the end,
therefore i++ was not transfered in the 2nd line to give undefined behaviour.... plus.. the condition in ternary which is
not evaluated ... is the one on the other condition.... printf is also allowed in comma operations just like all other
function calls. Sequence point exist between commas too...

130.Repeated ques.

131.fork() operation creates a child process and a parent both printing the world..

132.remember the path of for.. first intiailization ->condition->body->increment->condition->body and so on...

133.Follow recursion and remember integral division...

134.switch can be inside switch... break occurs to the nearest break...

135.Nothing new &>^>|

136.cons here outside means value is constant.. malloc is funtion there therefore strlen(a) is not affected by by malloc
assignment...strcat concatenates and returns the concatenated string, also it concates the first to the second overlapping
over null, the returned value is the concated string.. if both point to the same string, undefined behaviour... same with
strcpy 1st to 2nd.... the 1st one must have adequate memory otherwise overflow...

137.In macros replace as is without evaluating before and then evaluate the final expression..

138.function prototype can have int[]... all arrays passed as parameters to functions...

139.Inside string no macro replacement... others as expected.

140.Block scope concept... whatever is declared inside a scope remains inside....

141.Repeated ques.

142. Seg. fault because a null pointer is being used .... ***** with fp will not give seg fault because we do not perform
any increment operations to give unexpected results... here on making file with data and working, it will go to infinite
loop with all characters printed... EOF is basically a macro with value -1 which will be an int. however when unsigned
int taken... all values converted so no error...

143.Remember int (*) [2][3] is pointer to 2-D array while int (*(*)[2])[3] pointer to an array [2] having pointers to array
of [3] a is int (*)[2][3] pointing to first 2-D array,*a int(*)[3] , **a is int* and ***a is the first location, adding 1 will
respectively move first by 24, *a by 6 int * by 1 and in the last adds a value of 1 in ***a... Refer to q120 for more..

144.nothing new... <<2means x2^2

145.Again a is pointer to int.. so a will give address of 0 and *a as the value.. secondly, p is pointer to the first int*
pointer that stores the value of a(address of int 0) so p will have address of the new array formed, so p will give a diff
value then *p will have value a so same as a and **p will give *a which will give 0.while ptr is just a variable storing
p's value so same results.. so here diff of array type initialization and normal initializa=tion is shown...Also memory is
stored in the static memory location with arrays stored with a diffrence of one block in between and normal variables
continuosly.

146.initially ----- will give l value error as discussed offten give space after 3- and on solving hence the 1st part before
1st print will give output as expected... the line x-=x-- - --x is an undefined behaviour line so transfer it to the end... now
if you see the 3rd part, z will have 8 because first decrement then unary in x so -8 while y will give -1 .. finally
assignment will make it 8... Now talking about undefined behaiour in order of evaluation of arguments and existence of
no sequence point between expression of assignment.

147.Another example of undefined order of evaluation of arguments

148.Nothing great..

149.One think to be kept in mind is that hardcoded strings have static duration and therefore retained between function
calls while stack strings are auto duration so may be vanished...Now stack string so can be changed... the loop will work
only till 4 becaause strlen is continously being evaluated which works only till null.. so it will return 3 in subsequnet
calls and as soon as it becomes 4 it stops.

150.Nothing new

151.BAPQ nothing new.. strings not chaned or replaced

152.starting with 0 makes it an octal literal...%o if wish to be printed...

153.Starting with 0x makes it hexa octal.. %#x to print with 0x else without..X for capital x..

154.Repeated

155.Will not create any error... Because in pointer systems in c, storing in some other pointer affects only when
dereferenced more than expected or when you pefrom binary operations in which case it moves with the size oif the
memory it points to... So here no error because file** will have the correct value of file pointer which when passed via
fprintf is recieved as file* with warning but no error...

156. Nothing new.. just that all char constants converted to int and even char symbols before matching...

157.bitwise only work on integral types...when literals of diffent types ... it converts to corresponding types and
promotes to int and gives ans...20^020 will give 4..

158.Addition occurs as per the size of the one it points to so int* will move 4 for every 1 int(*)6 will move 4x6 24 for
evry 1 while int** will move 8 (on 64 bit) for evry 1.

159.Nothing unexpected.... moves with size of char and prints from b


160.It is a pure co-incidence that char variables single are initialized 0 though single however arrays of char given
random values... Can't be sure...

161. lvalue error...

162.Since B is a pointer it cannot have B.b .. otherwise normal ques...

163.l value error because of value... ++i will have its side effect completed before so might not have error...

164. ++i and i++ in for has no diff because in for all portions have sequence points beteen them so no diff...

165. firstly floating and pointer types cannot be in any form and way converted into one another...when dereferencing a
int into (int*) with int having &p, may cause error if both are of differnt size because on conversion to int* it will take a
size of 8 and cause error on dereferencing..therefore conersion from one type to another may not cause error in case of
pointers because all pointers are of same size but beware when you convert a non-pointer to a pointer type....

166.stringlizing operator used... comment replaced by space, strings concatenated at compile time, when wdth is less,
amd data more, overflow occurs, so no error... + for right alignment and - for left alignment.

167.Simple macro errors..

168.When in integral an f is there it is an error+ in float if UL types... then also error...An example of type promotion ,
float is just after double but before all 4 sized integers, therefore conversion occurs when error removed... type casting
occurs and not garbage reading 7 to 7.0000....

169.There are 4 reasons for a stdout associated buffer to be flushed, either fflush, \n, buffer filled, end of program, here
3rd part satisfied, therefore printed, however if we call another function which recurs without printing, nothing is
printed..,... seg. fault is because of buffer overflow attack.

170.Firstly , has expressions as arguments and not statements.. hence ; will create error.....if we replace () by {}..int is
compile time keyword with no meaning to preprocessor, hence no error... and it swaps...

171.No error because else part of ifdef works

172." gb""dtg" are concatenated, printf takes in one control string and all others as arguments.... so warning but no
error...in c++ also warning..

173.In ques if we go normally, the result is as expected... but what if we write xstr(str) or str(xstr()) it works as per the
rules in 85 ques..In case of str, it will stringlize straightaway so no prob... but in case of 1st, it will first go inside and
stringlize and then deal with xstr which will convert ot str and then stringlize the string.If a string is stringalized, it
forms "\" \"" Also if in an arguement that demands one token, you pass two together as argument.. such that they do not
convert to one in any manner... in that case both are passed and evaluated as an argument but with all spaces reduced to
1 between them... Also # does not only work on the single token but rather entire argement is stringlized.

174. Firstly void can have no variables, no typecasting, and no normal datatype kind operation. Void pointer will work
like normal pointers except that it cannot be dereferenced... Although void ** can be... plus, in order to perform
operations of pointers here too, size of void is taken as one... same is the case with functs.. but in func pointers,
dereferencing gives address of function.. so void pointers traverse by 1 ... Also remember general formula for p-q where
p and q are pointers is p-q=ceil((p value-qvalue)/sizeof(what it is pointing to))
rememver this ceil.. therefore p=10 and q=13 then p-q=-1 ...

175.In c, NULL is a macro defined in stddef.h as (void*)0 and therefore is expected to work as a pointer... even c++
assumes it as a pointer although defintion diff... In if else, it can take in both 0 and void* 0 so no warning... however
when used with arithmetics, although pointer, it is implicitly typecasted to 0. Not even an error in c++ because of
different defintion.Although value is same null character and NULL are diff... one is character and one a value to
pointer tyoes...

176. Main without a return is allowd...it returns 0 by default...

177.if extra star, it firstfills the xtar, then takes value.. in scanf to ignore input...

178.constant variables cannot be changed. In c++, their value does matter... because they are replaced at compile time..

179.16 bit systems used to have the concept of far, near and huge poin ters as they had differetn segments of 2^16 each
and therefore re3quired elaborate methods of pointing and
offset..http://stackoverflow.com/questions/1749904/difference-between-far-pointer-and-near-pointer-in-c..In 32 and 64
bit systems this is no longer an error because the entire memory cn be easily referenced...

179.So error..

180.Already discussed in extern static discussions.. extern has extern linkage and has to point somewhere... in lack of
which this will create linkage error...cannot add int i inside main becuse no linkage then external linkage...

181.All points discussed under fnction prototype defintiion... this is type 2 discussion...(call before prototypes)... One
exception found that when void is the function return type , it gives warning but as per default promotion, must also not
allow float, etc. as in case of int... because it is allowing them too....but that is highly undefined and must not be given
heed..

182.Switch statements are like goto linkings as they only start at the matching case and end at break or end of switch
block... Ignores the previous statements...

183.= has lower precedence to ternary.. here error is on b=2 and not b=1 because assignment has associativity from right
to left.. remember this..therefore error is created when 1:b is found as l value...

184.division has associativity from left to right.. in integer it gives quotient... macro expansion as expected to form right
identifier...

185. undefined behaviour in evaluation of arguments and no sequence point in assignment...

186. size will be 28... initialization will such that it occurs sequentially.... so if empno. was the first one, then the address
of the readonly string would be stroed in empno.. which can be retrieved by dereferencing the typecasted empno.Also
remember unix is a macro with predefined 1 same as linux... to use unix variable in program, undefine it...

187.The size will be that of the largest...arrangement of chars will be as per the endianess of the system although the
arrangemet is that 1st byte with first and so on... but how is long stored depends on endianess...

188. http://publications.gbdirect.co.uk/c_book/chapter6/initialization.html-Must read!!! All about initialization... As per


this, all switch statements are integral constants.. while initialiers may have arithmetic, integral or address constants.. in
address constants, it must be kept in mind that because addresses of global variables obtained during compile
time(allocated at compile time), therefore their memory can be used, along with functions however the value of a
variable although storing the same constant cannot be accessed... * deref. cannot be done, unless with &, casts are
allowed.. the crux is that in all, address constants should only have addresses and should NOT ACCESS ANY
VARIABLES' VALUE... Compile time and runtime constant differs... the process of initialization in arrays etc. can be
seen by the fact that first the compiler reads the no. of elements in intializer list if not mentioned and then allocates that
much memory...then it returns to the name of the arr the address of 1st location, therefore now in initialization this
variable is usable, the initailization occurs from left to right... one by one, the comma seperators here are like sequence
points.. In runtime it is just like writing statements for each memory location separately...The extra initializers are
simply discarded without evaluation... Sizeof does not evaluate the sizeof of the same array inside initializer list as it
calls it incomplete..However after that it can... in runtime, one can even assign value to forthcoming memory
beforehand however that will be overwritten... So sizeof to the same variable's whose initializer it is, is not possible..
typecasting occurs in expressions.. sizeof is unary operator.. unary postfix increment >prefix increment... As in ques,
basically the array name is an address constant and therefore can be used, however had this address constant been stored
in some pointer and then used, it would have given an error, as it would have been a variable and not a constant whose
value is accessed.. even constant variables not in compile time so not allowed... so arr is allocated a value and this can
be used for initialization... also keep in mind that that the initialization is compile time not runtime....

189. Explanation same as above only diff is . and ->operators in both...

190.follow normal switch operations... escape sequences basically characters representing some other character... in 2
types... \nnn means nnnis an octal no. representing the character if illegal character found then it ignores /. if \xnn here
nn represents the hexa no. \x with no digits is an error...the no. must be uptil 256 range if more, overflow occurs...

191.Simple recursion ques.. draw tree to see that q is the length of division, which in the last three exceeds to 25,26,27
indexes thus giving unpredictable answers..

192. all block typ statements without bracket only cover the next or sudcceding statement..thus if in for and for in for
and printf outside all brackets, therefore 1 printed only once...1 because of the condition...

193. printf can be given multiple arguments but the arguemnts worked upon depends on the control string,.... Read
va_arg...

194.pointer to hard coded string hence gives seg. fault... make it array and then proceed, swap will exchange, now
exit(1) has the task of exiting with the 1 return status,... what is imp is that if we remove \n and fflush then also printed,
it means exit flushes all buffers and destructs all stacks before exiting , unlike interrupts...otherwise normal working..

195.As was discussed in initializers, in case of string constants specifically, when memory location denotes pointers,
then address is stored but in case of char memory, if address of string is obtained, then elements are stored sequentially
in array.... char *s="erfer" char s[]="wfe" and char *s={"wefw"};--> {{'w','e','f','w'}}

196. Repeated ques..

197.shifting right follows sign extension, left does not, if more than 32 shift then modulo 32 shift allowed....therefore
always -1 to -1,,, take are while calculations...

198.The value will for sure be incremented, there is no undefined behaviour, because in ternary there exists a sequence
point, in between operators ? and :, otherwise all normal...

199. http://publications.gbdirect.co.uk/c_book/chapter9/stdarg.html -take care of argument promotion, although does not


give an error, although while execution, it gives illegal instruction, because in va_arg it gives error... read carefully. All
are macros..va_start variable must be given the variable just before ellipses, to specify the start location of arguments...
there is no argumets to note the no. of arguments sent, one must make one on one's own...
http://www.codeproject.com/Articles/4181/Variable-Argument-Functions===V.Imp,although background fnctioning
can be assumed as shown, modern compilers have in_built functions that can take in all data types and initialize at the
right position...
https://msdn.microsoft.com/en-us/library/kb57fad8.aspx
https://msdn.microsoft.com/en-us/library/fxhdxye9.aspx
http://publications.gbdirect.co.uk/c_book/chapter9/stdarg.html
Important here is that initilaizes the va_arg pointer if not set it gives seg fault....There must be atleast one named
arguemnt.even complex ddata types like function pointers also work...

200.http://stackoverflow.com/questions/4196201/where-are-c-c-main-functions-parameters...Actual location of the


string taken as cla is implementation specific, however it is ensured that they are writable and static... depends on where
crt places them.. although argc and argv are in function stack.. but not the strings...char* pointers are of significance
because the string length is not fixed... in memory they are stored consecutively .. char ** means pointer to pointer to
char.. since argumetn is char *argv[] == char **argv no error..

201. repeated.

202.First as discussed *y gives l value therefore no lvalue error.. also putting brackets around a variable without any
expression inside or comma operator , etc. i.e. only a viriable inside (), is similar to writing a variable and does not
convert to its value... * even works on constants provided they are of pointer type... the error that * gives is not a pointer
type kind of error or not on floats error... else the ques remains that of call by value and address..

203.breaks down to 2 processes at the division..

204.easy prob.. 0 here is '0' not null

205. Predict very carefully.. break trhough condition, take care of ch++ and putchar

206.only remember octal starts with 0..

207.Undefined behaviour, repeated ques..

208. compilation error... calloc requires two arguments ( no. , size ) .. on clearing ans shows that calloc always
initializes with 0... as far as malloc is concerned, initialization is
indeterminate...http://stackoverflow.com/questions/8029584/why-does-malloc-initialize-the-values-to-0-in-gcc... naybe
for security reasons.. because fresh block therefore 0.. Also rem to use calloc where malloc and memset used..
initializing with 0 takes overhead time...

209. Convert to subscript form for quick solving...

210.Swapping, without using third variable, call by ref.

211.&>^>|>&& rest same..

212.Beautiful ques!!!

213.displays binary representation...if bit present or not...

214.nothing worthwhile!!

215.Question of evluation of operands in the 1st case and associativity in the second....

216.Each open with w, reinitializes the pointer to the file end with file start... so in a way previous memory erased.. until
closed, the A and b remain in buffer and on the basis of closure , the file is written...one overwrites the other and puts
pointer to immediate end of one, therefore other file completely lost..

217. Question of sequence point, repeated...

218.This proxy initialization is possible in c because of pointer conversion(implicit) and runtime const variable...
However in c++ const variable is compile time variable therefore value remains unchanged although pointer conversion
via typecasting done to allow this process...c++ Vs. c...Although not noted in symbol table..

219.static variable is retained between function calls...draw a graph and you will observe that it is a tree... or for 0 it is 1,
for it is 2, for 3 it is f0+f1+f2+1 and so on.....so it comes out to be 128
220.Nothing new..

221.Please take great care while incrementing and checking value..learn to use paper and pen, can take an address and
then evaluate for fast evaluation..finding strlen, no seg fault as no change...

222.normal incrementing ques..

223.Shows diff between typecasting and normal printing without typecasting... the same memory interpreted
differently...

224.Convert both to pointer form and then check the address before dereferencing... basically we have just reversed the
two.. Now when we convert from pointer to non-pointer, 32-bit and 64-bit matters... in 32 bit systems, ans will come as
expected...but in 64, it will overflow therefore seg. fault...

225.else with ; means no statement... if aligns with the nearest if....

226.firstly this is not an error but seg fault..(invalid pointer error)... basically malloc has some overhead memory where
the block is associted with the length, type,etc. which is used by free to deallocate and add to garbage collector..
therefore it does not work on stacks.. or middle of block pointers.... only memory allocated through malloc and calloc
can be freed in its original form...

227.it is undefined behaviour because the index 99 is exceeding out of bounds toherwise if 0, it would have given 1.

228.usual feature, expected ans.

229.Expected feature

230.enum tag with no variable but still the variables or tags have values assigned... so replaced during compile time..
without tag also it works, just like preprocessing constants...Although there are quite differences in scope, memory and
debug time...

231.Undefined behaviour , no seq. points in between...

232.Short circuitng ques.

233.theircannot be cont. and break, without loop, while is replaced by if. There is also a function named getline in
stdio.h so a previous declaration of a different prototype is already there owing to which, this present function with the
same name will create conflict even if function writeen before call, solution is either to comply with the declaration of
the declared function as is, or to change the name of the function..Secondly no memory has been allocated for the this 1
and this 2 to input lines so it will give seg. fault...https://blog.udemy.com/c-getline/ for getline

234.http://www.tutorialspoint.com/c_standard_library/c_function_fwrite.htm &
http://www.tutorialspoint.com/unix_system_calls/read.htm read open and close too... all these are system calls... fwrite
is not...fileno() for file descriptor...the mode string may contain non-meaningful chars but must have the first chars
meaningful else error..

235. First fudge then print then pr, finally as expected...

236.sequence point between function call and body execution.. Also, the return value is not given, it may have random
value based often what was stored in the return register... so implementation defined...

237.Simple macro replacement , brackets are also replaced...


238.The inner i has different block scope and outer i has diff. A variable seizes to exist at the end of the scope and when
recalled, a new memory is formed.. local overpowers global...

239.https://gcc.gnu.org/onlinedocs/cppinternals/Token-Spacing.html- About + +9..So this is basically a question of


paste avoidance... Until ## or # used, the proprocessor assumes that number of different tokens before and after the
replacement of arguments as well as expansion of macros is conserved, therefore if it finds a point where the tokens are
being pasted and they should not have been, then it adds a space.. - and then -9 would have formed a single token --
therefore difftentiated by space...The preprocessing lexer first finds all valid tokens and removes addition spaces
between tokens to 1 space, all comments are removed, all multi-line tokens are pasted.. Now macro expansion takes
place preserving the number of tokens before and after and the spaces too... So if tokens seem to be pasted if together,
an extra space is added....But that requires formation of valid token, a token like -+is invalid so no space added but -= is
valid so - =9

240.in for, first initialization, then condition->body->increment->b

241.Flow as per the execution..

242.All C library functions are statically linked.. the libraries are static libraries that is they all attached with the
executable or loaded during runtime but remain combined and are included during linking process wherein their
functions are used for resolution.. When we provide declaration, we tell the compiler about the presence of the function
in this or other file therefore on including header files, in a way these functions are present so in that case no other
function of the same name can be written.. as declarations will be conflicting... Had there been two files with same fun
name compiled simuntaneously redeclaration error would have come, but in case of built in static functions, they only
throw warning of conflict and not error if the header of decl. not included... in that case if another function or variable of
the same name is present in the knowledge of the compiler, then the term shall be linked to that ... However if they are
not present or if they are declared and defined after function call, an implicit declaration is created which binds with the
library function and not the present function... Unexpected behaviour may be obtained due to mismatching of types
although no error of defsult promotion, etc. will be obtained...This is a way by which we can name functions with the
same name as lib. functions...This also makes it essential to include header files... In the ques.. fabs called the original
function and not fabs(int), other two questions of macro expansion...

243.static and const do exist with each other...About shift operation, firstly left shift always adds 0 at the end while right
adds 1/0 depending on previous bit in signed and 0 always in unsigned(sign extension in signed)... there can not be float
operations.. In typecasting to char or short that memory is truncated, shift is always on 32 bit.. so does not stoip at 8 for
char... the no. by which it is shifted is always modulo 32, in case of -ve to the nearest lI of 32...(sum)...Here because
unsigned therefore 58 else 6... use hexa multiplication for solving..

244. Simple solution of union and struct...

245.ternary>assignment

246.putting brackets around fun name does not matter, the scope of macro is from the line where it is defined till first
redefinition...

247.In switch, match directly jumps to the label and executes uptil end or break..

248.Simple

249.repeated

250.first is always control string and second replace argument.. there cn be no replacement in 2nd...

251.Just traversing
252.int * p,q makes it int *p and int q... when dereferned, this gives error..

253. strchr finds the first occurence of char from the end nd returns its pointer, rest is easy...

254.str in an array is constant pointer to char i.e. pointer value is constant although memory it points to is
variable..therefore reassigning gives error...

255.pointers point to hard coded string in read-only area to which strcat is amending therefore seg. fault..

256.Although pointer via which we sent is const...the declaration of strcpy demands char* to be non-const for copying
therefore it converts to char* without the need ot typecasting.. basically const qualifier is discarded in this case with
warning..So constant string can be sent to non-const. even in presnece of declaration..

257.the token after else is if..therefore elseif formed...now solve normally.. if else ladder

258.convert ot pointer form- both yield the same thing..

259.Normal increment, call by reference..

260.In structs if we are only giving declaration, it is not important to put ; at the end...

261. printf is solved from inner to outer, the return is no. of characters in tis case 3 which is input to outer printf and so
final ois 2 and not 5...

262.BEST QUES: the fault is because we have made the format specifier as %d and accepting character c because of
which print expects c to be int* and overwrites 4 blocks of memeory instead of the allocated one of c...Now the
allocation is such that the memory of i is just after c, writing c every time within 256 overwrites the following memory
of i too.. since system is little endian, the i always initializes back to 0 until no. >=256 not given, although incremented
it again goes back to 0 or 1 as per overflown bits... So the crux is to be very careful of the format specifier too, espically
in places where format specifier indicates higher memory than the pointer sent...

263.Normal..comment replaced by space..

264.Read first paragraph about pointers..since p and &p have same values and pp is int ** pointer therefore *pp will
give value at p, i.e. a ... Had pp been int* (*)[6] pointer value of *pp would have been p and not *p... Therefore 1st is
0..2nd is pp-p now pp stores &p which is p-p=0 ,pp is ** therefore value given here=0, incrementing pp is incrementing
in form of int* therefore it will technically be p+4... solve second accordingly...
*********************************
CONCEPTUALIZATION: memory stores value along with their types.. Pointer types have operations associated with
them in the form of the kind of pointer...in arrays: p is basically the pointer to location in int* and &p is pointer to that
same location in int(*)[6], in 2d, a is a pointer to that location in int(*)[6], &a is pointer in int(*)[6][6], *a in int* , the
point here is that until a new memory is allocated for a pointer, (which covers up mostly these array kind of cases), a
and &a and *a usually point to the same memory location...3d also a,*a,**a,& will have the same address but different
pointers...Perhaps this is the only exception in case of arrays...
**IMPORTANT: There is difference between function pointers and pointer to functions.. pointer to functions can
normally be said as pointer to function pointers... pointer to functions act like normal pointers of 8 bytes... also array of
functions is always that of pointer to functions...&function pointers and funcion pointers and infinite **** of function
pointers gives the same address, while in pointer to functions since new memory is allocated, therefore & has different
value...
**function pointers are in nutshell, constant pointers with *, ******, name and & having same address and size=1,
different from pointers to functions..functions called by function pointers and not pointer to functions until they store the
address of a function pointer....
solution to all function pointers:http://stackoverflow.com/questions/2795575/how-does-dereferencing-of-a-function-
pointer-happen
(*******sam)();
(*k)();
(&sam)();
k();
call same function sam... In short function pointers are immutable while other pointers are not...
********************************

265.Simple repeated ques

266.The memories of trans because they were allocated inside function will have garbage, 98 and 100 expalanable, 3-
'0'=-45 but converts ti unsigned int, later implicitly converted to char as -45 again..

267.-45 is unprintable

268.Simple pointer question although this in c++ would have given error, because we are converting implictily from
const int* to int* thus getting warning..constant feature can only be seen when change is via that pointer... if through
another pointer ot same variable no error..

269.Follow recursion call, there is statement after call and execution always passes back to the function call position..

270.http://www.academia.edu/1740218/Register_storage_class_in_C-Point to be noted: Register have same scope, place


and point of declaration as automatic, rather similar to automatic.. only diff., is non-addressable, however, c++ allows &
on registers (register request ignored) and c does not.SO error here..
Also:about volatile:http://www.geeksforgeeks.org/understanding-volatile-qualifier-in-c/

271.All about linked list nothing great

272.comma evaluated p becomes 0

273. Evaluation of aruemnts is from right to left, therefore R goes 0 first then fun called and r's value changed which is
not affected in value, had R been on left ans would have been as expected...Undefined generally in case of those which
leave side-effects...

274.Question of short circuiting

275.question of padding, memory allocated in chunks of the largest member

276.too long a ques to check :p

277.parameter-list is the list of parameters that the function takes separated by commas. If no parameters are given, then
the function does not take any and should be defined with an empty set of parenthesis or with the keyword void. If no
variable type is in front of a variable in the paramater list, then int is assumed. Arrays and functions are not passed to
functions, but are automatically converted to pointers. If the list is terminated with an ellipsis (,...), then there is no set
number of parameters. Note: the header stdarg.h can be used to access arguments when using an ellipsis.
https://www-s.acm.illinois.edu/webmonkeys/book/c_guide/1.3.html
Some observations: IN both declaration and defintition, either all arguemnts have datatypes or none have any... As
discussed both should match... In cases of no datatypes, all are assumed to be int,. Return type imp in declaration and
not defintition...
The cases dicussed in behaviours on the basis of order of call, declared and function, remain same provided that atleast
one of them must have complete datatypes for calling to completely typcast, if compiler until call has no idea of
datatypes, then that may result in case 3...

278.Simple ques... string first incremented to pointer at interview then sent... meanwhile sequence point reacher and i
incremented...
279. Simple, 0 so original

280.convert to ASCII and solve..

281.extern is a request.. had it been before when there was none present, then extern linkage would have caused error
static after non-static, here after internal, extern linkage is requested so it is refused and solved..

282.convert to pointer form to check. And because it is variable no. of arguments so no error, but when the va_arg()
extracts from empty list, undefined result happens...

283. Switch statement allows you to jump to the particular case and then follow the lines later, if a loop is encountered it
works normally and only breaks from switch when a break is encountered in the block...

284.questions of block scope, static duration and function scope together, change of a block without a new declaration
follows the one nearest to it..

285.When declared outside a function then ; not needed after struct/union else ; is needed after struct/union... The
statements of struct and union do not define a scope and therefore anything declared inside them can be accessed within
the scop of that statement, however as block changes in if lese switch loops , etc. it is not possible in these... for enum
variables and constants too sci=ope rules of the two, structs follow..

286.Simple pointer in strings ques.. discussed.

287.a is a array of structs (use pen and paper for this question).. a points to a+1 a+1 to a+2 and a+2 to a so *p=a+1 *
(p+1)=a+2 and so on.. now *p =a+1 and a are interchanged so *p=abcd now and *p->sptr=a+1=stuv so abcd abcd stuv...

288.trick nothing else

289.repeated ques.

290.Be careful simple recursion

291.right to left, length

292.struct differentiates variables of same name..

293. Nothing in ques.

294. To check endianess... Little endian lower address=LB and cross in BE vice versa

295.Same address to both ...


-------------------------------------------------------------------------------
About strcat use in q256.This is basically an undefined behaviour arising due to not allocating enogh space for adding
str2 to 1 because of which the string of str2 while concatening overwrites its own memory...print memories of the two to
observe

NOTE >>

sizeof is compile time operator therefore even for extern int i it will give no error... it works with declaration just like
int
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Somil Gupta

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

EOF
_______________________________________________

Вам также может понравиться