Common & Uncommon in C'
Common & Uncommon in C'
Common & Uncommon in C'
‘C’
Company References
• SATYAM 2007
• WIPRO 2009/2010
• ADITI SYSTEMS 2009
• IBM 2008/2009
• I-FLEX SOLUTIONS 2009/2010
• TCS 2008/2009
• HP 2009
Which is the Latest C Standard
ANSI-ISO C 9x (C 99)
Define the following
12.36
char *ss;
int num = 40;
sprintf(ss, "%d", num);
What is correct in C: "void main()" or "int main()"?
"%d"+1 (or > 0) in the printf statement affects the program output
by considering "%d" as string and ignores the excess argument i.e.
123. Here 1 refers to the index i.e. 2nd character in the array or
string "%d"
int main()
{
printf("Hi Friends"+3);
return(0);
}
Ans: Friends
Answer : 30
Answer : a
int main()
{
int val=5;
printf("%*d",val,val);
return(0);
}
Here '*' specifies the precision. First val is the precision and
second val is the actual value. Thus it prints 5 BLANK SPACES &
then the value 5.
int main()
{
cout<<!(100==100)+1;
return(0);
}
Answer : 1
}
Answer : Sum=480
Here access format specifier is used in the scanf
statement similar to the access format specifier usage
in the printf statements.
int main()
{
int a=1,b=2,c=3;
c=(--a,b++)-c;
printf("%d %d %d",a,b,c);
return(0);
}
Answer : 0 3 -1
Expressions within the parenthesis are evaluated from
L->R but the rightmost value will be considered for
computation and the rest will be ignored.
int main()
{
int val=50;
void *ptr;
ptr=&val;
printf("%d %d",val,*(int *)ptr);
return(0);
}
Answer : 50 50
Here the void pointer is used to access the contents of
a integer variable. Note: void pointer can point to any
variable of any data type. Care should be taken during
type casting it.
void main() {
int a, b, c, abc = 0;
a = b = c = 40;
if (c) {
int abc;
abc = a*b+c;
}
printf ("c = %d, abc = %d\n", c, abc);
}
Answer : c = 40 and abc = 0
The function main( ) invokes other functions within it.It is the first function
to be called when the program starts execution.
malloc leaves the block of memory uninitialized, but calloc zero fills the
memory.
Because of this zero fill, calloc can be slightly less efficient than
malloc.
Why does C give better run-time performance then
Java?
There are three sorting methods all very fast and that are
useful in different situations. Those methods are quick sort,
merge sort, and radix sort.
Which is the parameter that is added
to every non-static member function
when it is called?
~some()
{
cout<<"some's destructor"<<endl;
}
};
Ans:
void main() some’s destructor
{
some s; some’s destructor
s.~some();
}
Define a way other than using the
keyword inline to make a function
inline.
Answer:
The function must be defined inside
the class.