C 语言经典例子

1330阅读 0评论2016-03-12 644924073
分类:C/C++

1.hello world
  helloworld.c
 
#include "print.h"

int main(void){
 printHello();
 return 0;
}

print.c
#include "print.h"

void printHello()
{
 printf("hello word!\n");
}

print.h
#include "stdio.h"

void printHello(void);

gcc helloword.c print.c  print.h -o helloword
./helloword
hello word!


2.打印字符串
/* */
#include
main()
{
 char ch,nch; /* */
 int count; /* */
 int k;  /* */

 printf("Please input a string with a # in the end.\n");
 scanf("%c",&ch); /* */
 while(ch != '#') /* */
 {
  if(ch >= '0' && ch <= '9')
  {
   /* */
   count = ch-'0'+1; /* */
   scanf("%c",&nch); /* */
   for(k=0;k   }
  else
   printf("%c",ch); /* */
  printf(" ");   /* */
  scanf("%c",&ch);  /* */
 }
 printf("#\n");    /* */
}
  
#include
main()
{
 int a=5,b,c,i=10;
 b=a++;
 c=++b;

 printf("a = %d, b = %d, c = %d\n",a,b,c);
 printf("i,i++,i++ = %d,%d,%d\n",i,i++,i++);
 printf("%d\n",++i);
 printf("%d\n",--i);
 printf("%d\n",i++);
 printf("%d\n",i--);
 printf("%d\n",-i++);
 printf("%d\n",-i--);
 getchar();
}

./7
a = 6, b = 6, c = 6
i,i++,i++ = 12,11,10
13
12
12
13
-12
-13
c

             

上一篇: inittab脚本启动解析
下一篇:结构体指针的定义和引用