Oct 16, 2013

Subscribe to C Programs updates via Email

Good news programmers! Now you can get C programs in your inbox!

Yes, now you can subscribe to our updates via Email. It's very simple. Enter your email-id in the box below and click on "Subscribe" button.
Enter your email address:


Delivered by FeedBurner

This form is also available on the right side bar of the site. To get regular updates on new C programs, you can

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

Jan 22, 2013

C Aptitude: Endianness, Pointer Arithmetic

C Aptitude 31
In this episode we'll learn learn more about Endianness, Pointer Arithmetic.

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 31.1
  
main() {
    int i = 258;
    int *iPtr = &i;
    printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}   
Answer: 2 1

Explanation: The integer value 257 can be represented in binary as, 00000001 00000001. Remember that the INTEL machines are ‘small-endian’ machines. Small-endian means that the lower order bytes are stored in the higher memory addresses and the higher order bytes are stored in lower addresses. The integer value 258 is stored in memory as: 00000001 00000010.

C aptitude 31.2
main() {
    int i=300;
    char *ptr = &i;
    *++ptr=2;
    printf("%d",i);
}
Answer:556

Explanation:The integer value 300  in binary notation is: 00000001 00101100. It is  stored in memory (small-endian) as: 00101100 00000001. Result of the expression *++ptr = 2 makes the memory representation as: 00101100 00000010. So the integer corresponding to it  is  00000010 00101100 => 556.

C aptitude 31.3
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 ‘\0’. So the value of ‘str’ is less than that of ‘least’. So the value of ‘least’ finally is 0.
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 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

Jan 4, 2013

C Aptitude Questions and answers with explanation

C Aptitude 30
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 30.1
  main()
{
    int i;
    i = abc();
    printf("%d",i);
}
abc()
{
    _AX = 1000;
}

Answer:1000

Explanation: Normally the return value from the function is through the information from the accumulator. Here _AH is the pseudo global variable denoting the accumulator. Hence, the value of the accumulator is set 1000 so the function returns value 1000.

C aptitude 30.2
   main( )
{
    void *vp;
    char ch = ‘g’, *cp = “goofy”;
    int j = 20;
    vp = &ch;
    printf(“%c”, *(char *)vp);
    vp = &j;
    printf(“%d”,*(int *)vp);
    vp = cp;
    printf(“%s”,(char *)vp + 3);
}
Answer: g20fy

Explanation: Since a void pointer is used it can be type casted to any other type pointer. vp = &ch stores address of char ch and the next statement prints the value stored in vp after type casting it to the proper data type pointer. the output is ‘g’. Similarly the output from second printf is ‘20’. The third printf statement type casts it to print the string from the 4th value hence the output is ‘fy’.

C aptitude 30.3
     # include<stdio.h>
aaa() {
    printf("hi");
}
bbb(){
    printf("hello");
}
ccc(){
    printf("bye");
}
main()
{
    int (*ptr[3])();
    ptr[0]=aaa;
    ptr[1]=bbb;
    ptr[2]=ccc;
    ptr[2]();
}
 
Answer: bye

Explanation: ptr is array of pointers to functions of return type int.ptr[0] is assigned to address of the function aaa. Similarly ptr[1] and ptr[2] for bbb and ccc respectively. ptr[2]() is in effect of writing ccc(), since ptr[2] points to ccc.

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

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