What is a void pointer? Why can't we perform arithmetic on a void * pointer?
Program to check if the stack grows up or down
#include
#include
void stack(int *local1);
int main()
{
int local1;
stack(&local1);
exit(0);
}
void stack(int *local1)
{
int local2;
printf("\nAddress of first local : [%u]", local1);
printf("\nAddress of second local : [%u]", &local2);
if(local1 < &local2)
{
printf("\nStack is growing downwards.\n”);
}
else
{
printf("\nStack is growing upwards.\n”);
}
printf("\n\n”);
}
How can we sum the digits of a given number in single statement?
int sum=0;
for(;num>0;sum+=num%10,num/=10); // This is the “single line”.
To swap the two nibbles in a byte
#include
unsigned char swap_nibbles(unsigned char c)
{
unsigned char temp1, temp2;
temp1 = c & 0x0F;
temp2 = c & 0xF0;
temp1=temp1 « 4;
temp2=temp2 » 4;
return(temp2|temp1); //adding the bits
}
int main(void)
{
char ch=0x34;
printf("\nThe exchanged value is %x”,swap_nibbles(ch));
return 0;
}
What is a NULL pointer? How is it different from an unitialized pointer? How is a NULL pointer defined?
WAP to check whether string is palindrome
A program to print numbers from 1 to 100 without using loops
Method1 (Using recursion)
void printUp(int startNumber, int endNumber) { if (startNumber > endNumber) return; printf("[%d]\n", startNumber++); printUp(startNumber, endNumber); }
Method2 (Using goto)
`
void printUp(int startNumber, int endNumber)
{
start:
if (startNumber > endNumber)
{
goto end;
}
else
{
printf("[%d]\n”, startNumber++);
goto start;
}
end:
return;
}`