MCQs
When an automatic structure is partially initialized remaining elements are
initialized to 0(zero).
extern int a; indicates that the variable a is defined elsewhere, usually in a
separate source code module.
printf("%d`setminus`n", a); it prints the value of local variable int a = 20. Because, whenever
there is a conflict between local variable and global variable, local variable gets the
highest priority. So it prints 20.
Any pointer size is 2 bytes. (only 16-bit offset)
So, char *s1 = 2 bytes.
So, char far *s2; = 4 bytes.
So, char huge *s3; = 4 bytes.
A far, huge pointer has two parts: a 16-bit segment value and a 16-bit offset value.
Since C is a compiler dependent language, it may give different output in other platforms.
The above program works fine in Window (TurboC), but error in Linux (GCC Compiler).
Linker Error : Undefined symbol 'i'
The statement extern int i specifies to the compiler that the memory for 'i' is allocated
in some other program and that address will be given to the current program at the time
of linking. But linker finds that no other variable of name 'i' is available in any other program
with memory space allocated for it. Hence a linker error has occurred.
enum takes the format like {0,1,2..) so pass=0, fail=1, atkt=2
stud1 = pass (value is 0)
stud2 = atkt (value is 2)
stud3 = fail (value is 1)
Hence it prints 0, 2, 1
A function prototype in C or C++ is a declaration of a function that omits the function
body but does specify the function's name, argument types and return type.
While a function definition specifies what a function does, a function prototype can be
thought of as specifying its interface.
extern int x; - is an external variable declaration.
double pow(double, double); - is a function prototype declaration.
Therefore, 1 and 3 are declarations. 2 is definition.
Declaring is the way a programmer tells the compiler to expect a particular
type, be it a variable, class/struct/union type, a function type (prototype) or
a particular object instance. (ie. extern int i)
Declaration never reserves any space for the variable or instance in the
program's memory; it simply a "hint" to the compiler that a use of the variable
or instance is expected in the program.This hinting is technically called "forward
reference".
- During declaration we tell the datatype of the Variable.
- During definition the value is initialized.
C data types classification are
- Primary data types
- int
- char
- float
- double
- void
- Array
- Pointer
- Structure
- Union
- Enum
(i.e.long int l = 2.35; is the answer.)