1. Difference between pass by
reference and pass by value?
Ans: Pass by reference passes a pointer to the value. This allows the callee to modify the variable directly.
Ans: Pass by reference passes a pointer to the value. This allows the callee to modify the variable directly.
Pass by value gives a copy of the value
to the callee. This allows the callee to modify the value without modifying the
variable. (In other words, the callee simply cannot modify the variable, since
it lacks a reference to it.)
2. What is static identifier?
Ans: A file-scope variable that is declared static is visible only to functions within that file. A function-scope or block-scope variable that is declared as static is visible only within that scope. Furthermore, static variables only have a single instance. In the case of function- or block-scope variables, this means that the variable is not “automatic” and thus retains its value across function invocations.
2. What is static identifier?
Ans: A file-scope variable that is declared static is visible only to functions within that file. A function-scope or block-scope variable that is declared as static is visible only within that scope. Furthermore, static variables only have a single instance. In the case of function- or block-scope variables, this means that the variable is not “automatic” and thus retains its value across function invocations.
3. Where is the auto variables
stored?
Ans: Auto variables can be stored anywhere, so long as recursion works. Practically, they’re stored on the stack. It is not necessary that always a stack exist. You could theoretically allocate function invocation records from the heap.
Ans: Auto variables can be stored anywhere, so long as recursion works. Practically, they’re stored on the stack. It is not necessary that always a stack exist. You could theoretically allocate function invocation records from the heap.
4. Where does global, static, and
local, register variables, free memory and C Program instructions get stored?
Ans: Global: Wherever the linker puts them. Typically the “BSS segment” on many platforms.
Static: Again, wherever the linker puts them. Often, they’re intermixed with the globals.
Ans: Global: Wherever the linker puts them. Typically the “BSS segment” on many platforms.
Static: Again, wherever the linker puts them. Often, they’re intermixed with the globals.
The only difference between globals and statics is whether the linker
will resolve the symbols across compilation units.
Local: Typically on the
stack, unless the variable gets register allocated and never spills.Register:
Nowadays, these are equivalent to “Local” variables. They live on the stack
unless they get register-allocated.
5. Difference between arrays and
linked list?
Ans: An array is a repeated pattern of variables in contiguous storage. With an array, we can (on most architectures) move from one element to the next by adding a fixed constant to the integer value of the pointer.
Ans: An array is a repeated pattern of variables in contiguous storage. With an array, we can (on most architectures) move from one element to the next by adding a fixed constant to the integer value of the pointer.
A linked list is a set of structures scattered through memory, held together by pointers in each element
that point to the next element. With a linked list, there is a “next” pointer in each
structure which says what element comes next.
6. What are enumerations?
Ans: They are a list of named integer-valued constants.
Ans: They are a list of named integer-valued constants.
Example:enum
color { black , orange=4, yellow, green, blue, violet };
This declaration defines the symbols “black”,
“orange”, “yellow”, etc. to have the values “1,” “4,” “5,” … etc. The
difference between an enumeration and a macro is that the enum actually
declares a type, and therefore can be type checked.
7. Describe about storage
allocation and scope of global, extern, static, local and register variables?
Ans:Global: have application-scope. They’re available in any compilation unit that includes an appropriate declaration (usually brought from a header file). They’re stored wherever the linker puts them, usually a place called the “BSS segment.”
Extern: This is essentially “global.”
Static: Stored the same place as globals, typically, but only available to the compilation unit that contains them. If they are block-scope global, only available within that block and its subblocks.
Local: Stored on the stack, typically. Only available in that block and its sub blocks. (Although pointers to locals can be passed to functions invoked from within a scope where that local is valid.)
Register: See above on “local” vs. “register.” The only difference is that the C compiler will not let you take the address of something you’ve declared as “register.”
Ans:Global: have application-scope. They’re available in any compilation unit that includes an appropriate declaration (usually brought from a header file). They’re stored wherever the linker puts them, usually a place called the “BSS segment.”
Extern: This is essentially “global.”
Static: Stored the same place as globals, typically, but only available to the compilation unit that contains them. If they are block-scope global, only available within that block and its subblocks.
Local: Stored on the stack, typically. Only available in that block and its sub blocks. (Although pointers to locals can be passed to functions invoked from within a scope where that local is valid.)
Register: See above on “local” vs. “register.” The only difference is that the C compiler will not let you take the address of something you’ve declared as “register.”
8. What are register variables?
What are the advantages of using register variables?
Ans: If a variable is declared with a register storage class,it is known as register variable.The register variable is stored in the cpu register instead of main memory.Frequently used variables are declared as register variable as it’s access time is faster.
Ans: If a variable is declared with a register storage class,it is known as register variable.The register variable is stored in the cpu register instead of main memory.Frequently used variables are declared as register variable as it’s access time is faster.
9. What is the use of typedef?
Ans: The typedef help in easier modification when the programs are ported to another machine. A descriptive new name given to the existing data type may be easier to understand the code.
Ans: The typedef help in easier modification when the programs are ported to another machine. A descriptive new name given to the existing data type may be easier to understand the code.
10. Can we specify variable field
width in a scanf( ) format string? If possible how?
Ans: All field widths are variable with scanf( ). You can specify a maximum field width for a given field by placing an integer value between the ‘%’ and the field type specifier. (e.g. %64s). Such a specifier will still accept a narrower field width.
The one exception is %#c (where # is an integer). This reads EXACTLY # characters, and it is the
only way to specify a fixed field width with scanf( ).
Ans: All field widths are variable with scanf( ). You can specify a maximum field width for a given field by placing an integer value between the ‘%’ and the field type specifier. (e.g. %64s). Such a specifier will still accept a narrower field width.
The one exception is %#c (where # is an integer). This reads EXACTLY # characters, and it is the
only way to specify a fixed field width with scanf( ).
No comments:
Post a Comment