C program aptitude questions, answers and explanation for interview preparations.
In this site, We discussed various type of C programs, now we are moving into further steps by looking at the c aptitude questions.
This questions and answers are helpful to freshers and job hunters. C interview questions are from various companies and experts.
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.
C aptitude 1.1
void main()
{
int const * p=5;
printf("%d",++(*p));
}
Answer: Compiler error: Cannot modify a constant value.
Explanation: p is a pointer to a “constant integer”. But we tried to change the value of the “constant integer”.
C aptitude 1.2
main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer: mmmm aaaa nnnn
Explanation: s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].
C aptitude 1.3
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
Answer: I hate U
Explanation: For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double. Rule of Thumb: Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) .
Read more Similar C Programs
Learn C Programming
Recursion
C Interview questions
You can easily select the code by double clicking on the code area above.
To get regular updates on new C programs, you can Follow @c_program
You can discuss these programs on our Facebook Page. Start a discussion right now,
our page!
Share this program with your Facebook friends now! by liking it
(you can send this program to your friend using this button)
Like to get updates right inside your feed reader? Grab our feed!
5 comments on “C Aptitude Questions and answers with explanation.”
Write a program to find out the no of identical words in two files. The file name should be taken as command line argument ………………………could any one tell the solution for this
i loved this site,n really nice site……….
how can we get free free domain with free webhosting(free server) please rply me at my blog please……………
my info:http://nibastuyuu.blogspot.com/
Hello,
Please send this request to [email protected]
Write your requirement in detail.
Thanks!
Hello,
That question is out of scope of this website. However, you can write in your questions/suggestions to [email protected]
Thanks.
I have a one problem i want to make a program to draw a MAZE and FIND THE SHORTEST PATH using DIJKSTRA algorthm ..
please someone can help mee….and mail to me at [email protected]