# C Aptitude Questions and answers with explanation

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

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 27.1

` main(){    int i;    i = abc();    printf("%d",i);}abc(){    _AX = 1000;}`

Explanation: Normally the return value from the function is through the information from the accumulator. Here _AX 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 27.2
// If the inputs are 0,1,2,3 find the o/p

`  int i;main(){    int t;    for ( t=4;scanf("%d",&i)-t;printf("%dn",i))    printf("%d--",t--);}`

Explanation:Let us assume some x= scanf(“%d”,&i)-t the values during execution will be, t i x 4 0 -4 3 1 -2 2 2 0

C aptitude 27.3

`     int a,b;func(a,b){    return( a= (a==b) );}main(){    int process(),func();    printf("The value of process is %d !n ",process(func,3,6));}int val1,val2;process(pf,val1,val2)int (*pf) ();{    return((*pf) (val1,val2));}`

Answer:The value if process is 0 !
Explanation: The function ‘process’ has 3 parameters – 1, a pointer to another function2 and 3, integers. When this function is invoked from main, the following substitutions for formal parameters take place: func for pf, 3 for val1 and 6 for val2. This function returns the result of the operation performed by the function ‘func’. The function func has two integer parameters. The formal parameters are substituted as 3 for a and 6 for b. since 3 is not equal to 6, a==b returns 0. therefore the function returns 0 which in turn is returned by the function ‘process’.

`Read more Similar C Programs `
`Learn C ProgrammingC AptitudeC 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,

(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

# C program to print given numbers as a pyramid

Write a C program to print given numbers as a pyramid.
In this program we use the simple for statements to produce the patterns.
This program prints the following output,
1
232
34543
4567654
567898765
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

–>

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact info@c-program-example.com* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<stdio.h>void display(int start, char *str){        int i,j;            for(i=start; i<=(start+start); i++)        printf("%c",str[i]);        for(j=i-2;j>=start;j--)        printf("%c",str[j]);    }main(){        char str[]="123456789";        int i, j;        for(i=0;i<5;i++){                display(i, str);                printf("n");            }    }`
`Read more Similar C Programs `
`Graphics in CC Strings `
` `
`C Aptitude `
` `

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

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

# C Aptitude Questions and answers with explanation

C Aptitude 26
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 26.1

` 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);}`

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 26.2

`   main ( ){ static char *s[ ]  = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3);}`

Explanation:In this problem we have an array of char pointers pointing to start of 4 strings. Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. p hold the initial value of ptr, i.e. p = s+3. The next statement increment value in p by 1 , thus now value of p = s+2. In the printf statement the expression is evaluated *++p causes gets value s+1 then the pre decrement is executed and we get s+1 – 1 = s . the indirection operator now gets the value from the array of s and adds 3 to the starting address. The string is printed starting from this position. Thus, the output is ‘ck’.

C aptitude 26.3

`     main(){ int  i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i < n; ++i)   {printf(“%sn”,x);x++;   } }`

(blank space)
irl
rl
l

Explanation: Here a string (a pointer to char) is initialized with a value “girl”. The strlen function returns the length of the string, thus n has a value 4. The next statement assigns value at the nth location (‘’) to the first location. Now the string becomes “irl” . Now the printf statement prints the string after each iteration it increments it starting position. Loop starts from 0 to 4. The first time x[0] = ‘’ hence it prints nothing and pointer value is incremented. The second time it prints from x[1] i.e “irl” and the third time it prints “rl” and the last time it prints “l” and the loop terminates.

`Read more Similar C Programs `
`Learn C ProgrammingC AptitudeC 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,