Examples of Linux C programming examples

Source: Internet
Author: User

Example one: the implementation of character and integer variables

#include <stdio.h>intMain () {intc1,c2; CharC3; C1='a'-'A'; C2='b'-'B'; C3='C'- +; printf ("C1 is%d and C2 are%d\n", C1,C2); printf ("C3 is%d and%c\n", C3,C3); //characters exist in memory in ASCII code, a is 65, etc.//character variables can be calculated with integer variables    }

The result is:

32 32

C

The string constant is "" inside the

The character constant is "inside the

Example two:

" stdio.h " int Main () {  char  A, a=n, b=98; printf ("  %c%c\n", A, b);  printf ("%d%d"


Ab

9798

-------------------------------

Why do you want to add a ' \o ' to the end of a string constant because the string is stored in ASCII and has an end flag bit. It is hard to tell how much space the string occupies in memory.

Example three: pointer array and level two pointer "Linux C programming page 84th"

#include"stdio.h"intMain () {inta[5]={1,3,5,7,9 }; int*p[5],i; int**pp=p;//equivalent to int a=12;int *b=&a;int **c=&b; The last one here     for(i=0;i<5; i++) P[i]=&A[i];  for(i=0;i<5; i++) printf ("%d\n",*P[i]);  for(i=0;i<5; i++,pp++) printf ("%d",**pp);}

Example four: pointer and array relationships. Classic examples

#include"stdio.h"intMain () {//Classic example Linux C program on page 85th  inta[2][5]={1,3,5,7,9,2,4,6,8,Ten}; int(*p) [5],i;//Int (*p) [5] means p is a pointer to a one-dimensional pointer containing 5 elements, and P is the first address of a one-dimensional arrayp=A;  for(i=0;i<5; i++) printf ("%d",(*p)   [i]); printf ("\ n"); P++;//p plus 1, pointing to the second row of the two-dimensional array a    for(i=0;i<5; i++) printf ("%d",(*p)       [i]); printf ("\ n"); return 0; }

Examples of Linux C programming examples

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.