I have written the few codes First code is working as I suppose to do but getting errors in other codesThis is not the way to learn C keywords.
Read what the keyword does. Look at examples and explanations of what it does.
And if you don't see a difference, don't use it until you fully understand its purpose.
Example #1
C:
#include<stdio.h>
void delay (void)
{
unsigned int i;
for (i = 0; i < 6; i++)
{
printf("Loop : %d \n", i);
}
}
int main (void)
{
delay();
return 0;
}
Loop : 1
Loop : 2
Loop : 3
Loop : 4
Loop : 5
Example #2 Error What does it means invalid use of void expression ?
C:
#include<stdio.h>
void delay (void)
{
unsigned int i;
for (i = 0; i < 6; i++)
{
printf("Loop : %d \n", i);
}
}
int main (void)
{
delay();
printf("Loop : %d \n", delay()); // Error invalid use of void expression//
return 0;
}
error: void value not ignored as it ought to be
int count = delay (); // declaring variable to store function value
C:
#include<stdio.h>
void delay (void)
{
unsigned int i;
for (i = 0; i < 6; i++)
{
printf("Loop : %d \n", i);
}
}
int main (void)
{
int count = delay (); // declearing variable to store function value
printf("Loop : %d \n", count);
return 0;
}