C Aptitude Questions and answers with explanation

C Aptitude 13
C program is one of most popular programming language which is used for core level of coding across the board. C program is used for operating systems, embedded systems, system engineering, word processors,hard ware drivers, etc.

In this site, we have discussed various type of C programs till date and from now on, we will move further by looking at the C aptitude questions.

In the coming days, we will post C aptitude questions, answers and explanation for interview preparations.

The C aptitude questions and answers for those questions along with explanation for the interview related queries.

We hope that this questions and answers series on C program will help students and freshers who are looking for a job, and also programmers who are looking to update their aptitude on C program.
Some of the illustrated examples will be from the various companies, and IT industry experts.
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

 
Predict the output or error(s) for the following:

C aptitude 13.1

  ain()
{
int i=0;

for(;i++;printf("%d",i)) ;
printf("%d",i);
}


Answer: 1

Explanation: before entering into the for loop the checking condition is “evaluated”. Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).

C aptitude 13.2

   main()
{
char s[]={'a','b','c','n','c',''};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}


Answer: M

Explanation:p is pointing to character ‘n’.str1 is pointing to character ‘a’ ++*p meAnswer:”p is pointing to ‘n’ and that is incremented by one.” the ASCII value of ‘n’ is 10. then it is incremented to 11. the value of ++*p is 11. ++*str1 meAnswer:”str1 is pointing to ‘a’ that is incremented by 1 and it becomes ‘b’. ASCII value of ‘b’ is 98. both 11 and 98 is added and result is subtracted from 32. i.e. (11+98-32)=77(“M”);

C aptitude 13.3

   main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}

Answer: Compiler Error

Explanation: Initialization should not be done for structure members inside the structure declaration.

Read more Similar C Programs 
 
Learn C Programming
C Aptitude
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!

To browse more C Programs visit this link
(c) www.c-program-example.com

Leave a Reply