/* 1.
Branching and Looping */
#include <stdio.h>
void main()
{
int i;
for (i = 1; i < 4; i++)
{
switch (i)
{
case 1: printf("%d", i); break;
case 2: printf("%d", i); break;
case 3: printf("%d", i); break;
}
}
switch (i)
{
case 4: printf("%d", i); break;
}
}
/* 2. Operator and Expression */
void main()
{
char *s = "\12345s\n";
printf("%d", sizeof(s));
}
/* 3. Functions */
int main()
{
static int i = 3;
printf("%d", i--);
return i > 0 ? main() : 0;
}
/* 4. Pointers */
int main()
{
char *s[] = {"dharmendra", "hewlett-packard", "siemens", "ibm"};
char **p;
p = s;
printf("%s", ++*p);
printf("%s", *p++);
printf("%s", ++*p);
}
/* 5. Dynamic Memory */
#include <stdio.h>
#include <malloc.h>
#include <string.h>
int main()
{
int i;
char a[] = "String";
char *p = "New String";
char *temp;
temp = malloc(strlen(p) + 1);
p = malloc(strlen(temp) + 1);
strcpy(p, temp);
printf("%s", p);
}
/* 6. Algorithm */
int main()
{
int n = 12, res = 1;
while (n > 3)
{
n -= 3;
res *= 3;
}
printf("%d", n * res);
}
/* 7. Function */
void fun(int [][3]);
int main()
{
int a[3][3] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
fun(a);
printf("%d\n", a[2][1]);
}
void fun(int b[][3])
{
++b;
b[1][1] = 5;
}
/* 8. Strings */
void main()
{
int i, n;
char x[5];
strcpy(x, "Zoho");
n = strlen(x);
*x = *(x + (n - 1));
printf("%s", x);
}
/* 9. Arrays */
void main()
{
int c[] = {5, 4, 3, 4, 5};
int j, *q = c;
for (j = 0; j < 5; j++)
{
printf("%d", *c);
++q;
}
}
/* 10. Branching and Looping */
void main()
{
int i = 1;
for (i = 0; i = -1; i = 1)
{
printf("%d", i);
if (i != 1) break;
}
}