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 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. Or if you can’t find the program you are looking for, you can contact [email protected]. Thank you for visiting.
(c) www.c-program-example.com

C Aptitude Questions and answers with explanation

C Aptitude 29
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 29.1

  enum colors {BLACK,BLUE,GREEN}
main()
{

printf("%d..%d..%d",BLACK,BLUE,GREEN);

return(1);
}

Answer: 0..1..2

Explanation: enum assigns numbers starting from 0, if not explicitly defined.

C aptitude 29.2

   void main()
{
char far *farther,*farthest;

printf("%d..%d",sizeof(farther),sizeof(farthest));

}


Answer: 4..2

Explanation: The second pointer is of char type and not a far pointer

C aptitude 29.3

     main()
{
int i=400,j=300;
printf("%d..%d");
}

Answer: 400..300

Explanation: printf takes the values of the first two assignments of the program. Any number of printf’s may be given. All of them take only the first two.

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

C Program to delete a file using remove function.

Write a C program to delete a specified file using remove function.
remove function deletes the specified file, where it takes file name as the argument and if file is successively deleted it returns 0 , other wise returns a non zero value.
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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include<stdio.h>
#include<string.h>
int main()
{
    char file_name[40];
    printf("Enter the file name with location:n Example, c:example.txtnn");
    gets(file_name);
    if(remove(file_name) != 0 )
    puts("Error deleting filenn");
    else
    puts("File successfully deletednn");
    return 0;
}
Read more Similar C Programs
Graphics in C
C Strings
C Aptitude

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

C program without using main function

Write a C program without using main function.
In this program, we didn’t use the main function, but we are using the preprocessor directive #define with arguments to define the Main function.
A Preprocessor is program which processes the source code before compilation.
The ‘##‘ operator is called the token pasting or token merging operator. In the second line of program we used it to merges the 4th,1st,3rd & the 2nd characters(tokens), and it compiles as “msut”.
When the controller calls int begin, preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e). As defined in the macro decode it merges the 4th,1st,3rd & the 2nd characters, and int begin becomes int main(), so program runs successfully. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)

int begin()

{
printf(” Ha HA see how it is?? “);
}
Read more Similar C Programs

Graphics in C

C Strings
C Aptitude 

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

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

Answer: 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--);
}

Answer: 4–0 3–1 2–2

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 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

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 [email protected]
* 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 C

C Strings 
 
C Aptitude 
 

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

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

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

Answer: ck

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++;
}
}

Answer:
(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 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

C program to hide the mouse pointers.

C program to hide the mouse pointers.
In this program, we hide the mouse pointers using graphics.h and dos.h library functions.
To use graphics.h, we have to install the drivers in to the the system by using the initgraph() function.
In this program,we also check the condition that mouse pointer is available or not. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<graphics.h>
#include<conio.h>
#include<dos.h>

void showmouseptr();
void hidemouseptr();

union REGS i, o;

int main()
{
int count = 1, gd = DETECT, gm;

initgraph(&gd,&gm,"C:\TC\BGI");/*check your path, to install the drivers in to the the system*/

i.x.ax = 0;
int86(0X33,&i,&o);
if(o.x.ax == 0)
{
printf("nt Sorry! Mouse support not available !");
}
else
{
showmouseptr();

while(count<=10)
{
getch();
count++;
if(count%2==0)
hidemouseptr();
else
showmouseptr();
}
}

getch();
return 0;
}


void showmouseptr()
{
i.x.ax = 1;
int86(0X33,&i,&o);
}

void hidemouseptr()
{
i.x.ax = 2; // to hide mouse
int86(0X33,&i,&o);
}
Read more Similar C Programs
 
Graphics in C

C Strings

C Aptitude

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

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

C Program to change the text colors.

Write a C Program to change the text colors.
In this program, we give the example of changing the text colors, background colors using conio.h library.
Syntax: void textcolor(int_color);
Here color is the integer variable, you can specify a color name also, but it should be a proper color name in capital letters.
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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
textcolor(BLUE); // Change font colour to blue
textbackground(WHITE); //change the background colour to white
cprintf("Color is Blue with white backgroundnn");
clrscr();
textcolor(RED+BLINK);//this one is blinking the text
cprintf("Color is RED with blinkingnn");
return 0;
}
Read more Similar C Programs
 
Graphics in C

C Strings 
 
C Aptitude 
 

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