C Aptitude Questions and answers with explanation.

C Aptitude 3
C program is one of most popular programming language which used for core level of coding across the board. Now a days 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 3.1

   main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}

Answer: 0 0 1 3 1

Explanation:Logical operations always give a result of 1 or 0 . And also the logical AND (&&) operator has higher priority over the logical OR (||) operator. So the expression ‘i++ && j++ && k++’ is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value of m is 1. The values of other variables are also incremented by 1.

C aptitude 3.2

main()
{
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}


Answer:12

Explanation:The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.

C aptitude 3.3

  main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}



Answer:three

Explanation: The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn’t match.

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 find size-of an array.

Example programs to solve the problems of Arrays in C. In This program we, find the size of the array using sizeof() operator. Read more about C Programming Language .

/***********************************************************
* 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>
int main( )
{

int i,num;
printf("nEnter the hoe many elements you want?n");
scanf("%d",&num);

int a[num];
printf("nEnter the %d elements:n",num);
for(i=0;i<num;i++)
{
scanf("%d",&a[i]);
}
printf("Elements in array are:n");
for(i=0;i<num;i++)
{
printf("%dn",a[i]);
}
printf(" The size of the array is: %d Bytes.",(int)sizeof(a));

return 0 ;
}
Read more Similar C Programs
Array In C

Simple C Programs

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!

(c) www.c-program-example.com

C Program to Find out the size of the different data types

C Program to find the Size of Different data types. In This program we, find the size of the datatypes in c using sizeof() operator. sizeof() operator returns the its argument memory in bytes. Read more about C Programming Language .

/***********************************************************
* 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>
main()
{

printf(" short int is %2d bytes n", sizeof(short int));
printf(" int is %2d bytes n", sizeof(int));
printf(" int * is %2d bytes n", sizeof(int *));
printf(" long int is %2d bytes n", sizeof(long int));
printf(" long int * is %2d bytes n", sizeof(long int *));
printf(" signed int is %2d bytes n", sizeof(signed int));
printf(" unsigned int is %2d bytes n", sizeof(unsigned int));
printf("n");
printf(" float is %2d bytes n", sizeof(float));
printf(" float * is %2d bytes n", sizeof(float *));
printf(" double is %2d bytes n", sizeof(double));
printf(" double * is %2d bytes n", sizeof(double *));
printf(" long double is %2d bytes n", sizeof(long double));
printf("n");
printf(" signed char is %2d bytes n", sizeof(signed char));
printf(" char is %2d bytes n", sizeof(char));
printf(" char * is %2d bytes n", sizeof(char *));
printf("unsigned char is %2d bytes n", sizeof(unsigned char));
}
Read more  C Programs
Array In C

Simple C Programs

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!

(c) www.c-program-example.com