#include<stdio.h> int main() { char *str; str = "%d\n"; str++; str++; printf(str-2, 300); return 0; }
After sometime the stack memory will be filled completely. Hence stack overflow error will occur.
In a loop, there is no recursive call involved that saves a lot of time and space too.
Example:
#include <stdio.h>
int mul(int, int); /* Function prototype */
int main()
{
int a = 0, b = 3, c;
c = mul(a, b);
printf("c = %d\n", c);
return 0;
}
/* Two return statements in the mul() function */
int mul(int a, int b)
{
if(a == 0 || b == 0)
{
return 0;
}
else
{
return (a * b);
}
}
Output:
c = 0
int f1(int a, int b) { return ( f2(20) ); } int f2(int a) { return (a*a); }
Example:
#include <stdio.h>
int f1(int, int); /* Function prototype */
int f2(int); /* Function prototype */
int main()
{
int a = 2, b = 3, c;
c = f1(a, b);
printf("c = %d\n", c);
return 0;
}
int f1(int a, int b)
{
return ( f2(20) );
}
int f2(int a)
{
return (a * a);
}
Output:
c = 400
#include<stdio.h> int main() { char *str; str = "%s"; printf(str, "K\n"); return 0; }
#include<stdio.h> int main() { char str1[] = "India"; char str2[] = "CURIOUSTAB"; char *s1 = str1, *s2=str2; while(*s1++ = *s2++) printf("%s", str1); printf("\n"); return 0; }
#include<stdio.h> int main() { int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1)); return 0; }
#include<stdio.h> int main() { int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2}, {2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} }; printf("%u, %u, %u, %d\n", a, *a, **a, ***a); return 0; }
#include<stdio.h> #include<string.h> int main() { int i, n; char *x="Alice"; n = strlen(x); *x = x[n]; for(i=0; i<=n; i++) { printf("%s ", x); x++; } printf("\n", x); return 0; }
It may give different output in other platforms (depends upon compiler and machine). The online C compiler given in this site will give the Option C as output (it runs on Linux platform).
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.