C Programming and Computer Geeks

Search MY Blog

Friday, 29 November 2013

Faq On Array Addition and subtraction



what could be the output of the following program.

int main()
{
char *p = a;
printf("%s", p + p[5] - p[13]);
getch();
return 0;
}

Ans: It will display the below output
.neentech.blogspot.com

Array addition and subtraction

Explanation:  From the Statement p + p[5] – p[13], p points to address of array a . And p[5] contains/holds character ‘e’ and p[13] holds character ‘b’. So the final statement will be p + ’e’ – ‘b’ ==> p + 101 – 98 (here 'e' equals to decimal 101 & 'b' equals to Decimal 98) ==> p+3 ==> will give the address location of a[3]. So it will start printing the string from a[3].

Click here for more C Faq

Thursday, 28 November 2013

What getchar function returns and list out similar functions?



what is the Output of the following Program?

#include “stdio.h”
void main(void)
{
printf("\t %d ",getche());
getch();
}

ANSWER:  it will return the Equivalent ASCII decimal value of entered character..


getchar, getch, getche functions
getchar() Function

 
getch(), getche(), getchar() will return integer value.

getchar() returns the Equivalent decimal(ASCII) value of entered character with echoing the entered character.

getche() returns the Equivalent decimal(ASCII) value of entered character with echoing the entered character.

getch() returns the Equivalent decimal(ASCII) value of entered character without echoing the entered character.

Note: Here getchar() is ASCII C Standard Function. getche() and getch() functions are non-standard functions. so this program may not be compiled successfully in many Platforms.. This can be compiled
successfully in VC++ and Turbo C/C++ compilers...

Click here for more C Faq



Search This Blog