½âÎöCÓëC++ÖеĹؼü×Öconst
ÔÚCÓëC++ÓïÑÔÖж¼´æÔڹؼü×Öconst,ºÜ¶àÈ˶¼¶Ô´Ë¹Ø¼ü×Ö´æÔÚÒ»¸ö´íÎóµÄÈÏʶ£¬ÈÏΪÔÚCÓïÑÔÖйؼü×ÖconstÊÇʹ±äÁ¿×÷Ϊһ¸ö³£Á¿£¬¼´½«±äÁ¿³£Á¿»¯£¬¾ÍÏñºê¶¨ÒåÒ»Ñù¡£¶øÔÚCÓïÑÔÖеĹؼü×ÖconstËùÆðµÄ×÷Óò¢²»ÊÇʹ±äÁ¿³£Á¿»°£¬¶øÊÇÏÞÖƱäÁ¿£¬Ê¹±äÁ¿³ýÁ˱»¸³³õÖµÍ⣬ÎÞ·¨±»ÖØи³Öµ¡£
¶øÔÚC++Öйؼü×Öconst²»½öʹ¸Ã±äÁ¿ÎÞ·¨Ð޸ģ¬Ò²ÊÇʹ±äÁ¿³£Á¿»¯£¬¼´½«±äÁ¿¸³³õÖµºó¿ÉÒÔµ±×÷³£Á¿Ê¹Óã¬Ï൱ÓÚ½øÐÐÁ˺궨Òå¡£
ÔÚ±àÒëÆ÷ÖÐÊäÈëÒÔÏ´úÂ룬Äã»áÓиüÖ±¹ÛµÄÌå»á¡£
ÔÚCÓïÑÔ±àÒëÆ÷ÖУº
/* constÏÞÖƵıäÁ¿µÄÖµÎÞ·¨ÐÞ¸Ä*/
#include <stdio.h>
int main(void)
{
const int a=1;
int const b=1;
a=1;
b=1;
system("pause");
return 0;
}
µ±Ä㽫Õâ¶Î´úÂë±àÒëʱ£¬±àÒëÆ÷»á±¨´í£ºÔÚmianº¯ÊýÖÐÎÞ·¨ÐÞ¸ÄconstÏÞÖƵĶÔÏó¡£
×¢£ºÔÚCÓïÑÔÖУ¬¹Ø¼ü×Öconst±»·ÅÔÚ±êʶ·û֮ǰ»òÖ®ºóÊÇÒ»ÑùµÄЧ¹û¡£
/* constÏÞÖƵıäÁ¿ÎÞ·¨ÐÞ¸Ä*/
#include <stdio.h>
int main(void)
{
const int a=1;
switch(1)
{
case a:prinf("variable a can be used as constant");break;
default :printf("variable a cannot be used as constant");
}
system("pause");
return 0;
}
µ±Äã±àÒëÕâ¶Î´úÂëÊÇ£¬±àÒëÆ÷»á±¨´í£ºÔÚmainº¯ÊýÖÐÒªÇóʹÓó£Á¿¡£
¹Ø¼ü×Öconst¶ÔÖ¸ÕëµÄÏÞÖÆ£º
/*cosntÔÚ*Ç°£¬Ö¸ÕëÖ¸Ïò¶ÔÏóµÄÖµÎÞ·¨ÐÞ¸Ä*/
#include <stdio.h>
int main(void)
{
int a=1,b=2;
const int * p1=&a;
int const * p2=&b;
*p1=1;
*p2=1;
system("pause");
return 0;
}
constÔÚÐǺÅÇ°¶Ô¶ÔÖ¸Õë±äÁ¿½øÐÐÏÞÖÆʱÊǶÔÖ¸Õë±äÁ¿ËùÖ¸ÏòµÄ¶ÔÏó½øÐÐÏÞÖÆ£¬Õë¶ÔÉÏÁдúÂë¾ÍÊǶÔa£¬b½øÐÐÏÞÖÆ£¬Ê¹a£¬b²»Äܱ»ÖØи³Öµ£¬Òò´Ë±àÒëʱ»á±¨´í£ºÔÚmianº¯ÊýÖÐÎÞ·¨ÐÞ¸ÄconstÏÞÖƵĶÔÏó¡£µ«Á½¸öÖ¸Õë±äÁ¿µÄÖµÊÇ¿ÉÒÔÐ޸ĵġ£±àÒëÏÂÁдúÂ룺
/* cosntÔÚ*Ç°£¬Ö¸Õë±äÁ¿µÄÖµ¿ÉÒÔÐÞ¸Ä*/
#include <stdio.h>
int main(void)
{
int a=1,b=2;
const int * p1=&a;
int const * p2=&b;
printf ("a=%d\nb=%d\n",*p1,*p2);
p1=&b;
if(p1==p2)
printf("the address of p1 is equal to the address of p2\n");
system("pause");
re
Ïà¹ØÎĵµ£º
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
main()
{
FILE *fp;
if ( (fp = fopen( "c:\\a.txt", "r" )) == NULL ) printf("ERROR!\n");
int tmp[MAXSIZE];
int i;
for ( i=0; i<MAXSIZE; i++ )
{
tmp[i] = 0; ......
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<windows.h>
#include<malloc.h>
#include<math.h>
typedef struct worker
{
int num; //񅧏
char name[15]; //ÐÕÃû
char zhicheng[15];& ......
ÏÈÇ°ÔÚ²âÊÔmysql connect c++½Ó¿ÚµÄʱºòÔËÐÐÆä¹Ù·½ÌṩµÄÀý×Ó
21.5.5.6. MySQL Connector/C++ Complete Example 2
The following code shows a complete example of how to use MySQL Connector/C++:
/* Copyright 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify ......
EBCDIC (Extended Binary Coded Decimal Interchange Code) À©Ôö¶þ½øʽʮ½ø½»»»Â룬ΪIBMÓÚ1963Äê£1964Äê¼äÍƳöµÄ×Ö·û±àÂë±í£¬¸ù¾ÝÔçÆÚ´ò¿×»úʽµÄ¶þ½ø»¯Ê®½øÊý(BCD, Bindary Coded Decimal)ÅÅÁжø³É¡£ÊÇIBMÃÔ¶û¼¶ÒÔÉϵçÄԵıê×¼Âë¡£
ASCII£¨American Standard Code for Information Interchange£¬ÃÀ¹úÐÅÏ¢»¥»»±ê×¼´úÂë£©Ê ......
¸ñʽÊä³ö:
printf(¸ñʽ¿ØÖÆ, Êä³ö±íÁÐ);
%d Ê®½øÖÆÊý %md mΪָ¶¨µÄ¿í¶È ÈôÊý¾ÝλÊýСÓÚm,Ôò×ó¶Ë²¹ÒÔ¿Õ¸ñ;Èô´óÓÚm,Ôò°´Êµ¼ÊλÊýÊä³ö
%ld ³¤ÕûÐÍÊý¾Ý %mld Ö¸¶¨×ֶοí¶È
%o °Ë½øÖÆÕûÊýÐÎʽ %mo
%x Ê®Áù½øÖÆÕûÊýÐÎʽ %mx
%u unsignedÐÍÊý¾Ý,ËüÒ²¿ÉÓÃ%o»ò%x¸ñʽÊä³ö
%c Ò»¸ö×Ö·û ......