C Aptitude Questions and answers with explanation

C Aptitude 24
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.

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 how to prepare and write the C Aptitude Exams?
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 24.1

main()

{

char str[4]="test";

printf("%s",str);


}

Answer: test#$634278621@!

Explanation: The character array has the memory just enough to hold the string “test” and doesn’t have enough space to store the terminating null character. So it prints the test correctly and continues to print garbage values till it accidentally comes across a NULL character.

C aptitude 24.2

 
main()

{

char * str = "hello";

char * ptr = str;

char least = 127;

while (*ptr++)

least = (*ptr <least ) ?*ptr :least;

printf("%d",least);

}

Answer: 0

Explanation: After ‘ptr’ reaches the end of the string the value pointed by ‘str’ is ‘’. So the value of ‘str’ is less than that of ‘least’. So the value of ‘least’ finally is 0.

C aptitude 24.3

     main()

{

int i = 257;

int *iPtr = &i;

printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );

}

Answer: 11

Explanation: The integer value 257 is stored in the memory as, 00000001 00000001, so the individual bytes are taken by casting it to char * and get printed.

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

4 comments on “C Aptitude Questions and answers with explanation

Leave a Reply