C++小題(八)

10547 ワード

/////////////////////////////////////////////////////////////
/*
   "Hello"      ?
int main() {
 printf("Hello");
 fork();
 printf("Hello");
}
    : C       : C (  )
A2
B3
C4
D6
print          "
" , , 。fork 。 */ ///////////////////////////////////////////////////////////// /* for ? unsigned short i,j; for(i=0, j=2; i!=j; i+=5, j+=7) {} unsigned short i,j; for(i=3,j=7;i!=j;i+=3,j+=7) {} : A : A ( ) 32767 16383 32767 16363 33787 16363 33787 16383 :unsigned short 2^16 , 0~2^16-1,j i 2 ,i 5 ,j 7 , unsigned short 0( ) i、j , 7t - 5t + 2 = 216, 32767 (7t + 7)-(5t - 3) = 216, 16383 */ ///////////////////////////////////////////////////////////// /* java c++ , ? : B A java ,c++ B c++ java C Java , c++ D java ,c++ JAVA , , C++ ; JAVA , ,C++ ;C++ ,JAVA ; JAVA C++ , ;C++ JAVA 。 C++ ,JAVA , 。 */ ///////////////////////////////////////////////////////////// /* () : A A vector B map C vector D map vector , , ; map ,key value , , key value, , */ ///////////////////////////////////////////////////////////// /* : : A B D : B D ( ) A MyClass operator *(double ,MyClass); B MyClass operator *(MyClass ,MyClass); C MyClass operator *(double ,double); D MyClass operator *(MyClass ,double); c++ , 。 */ ///////////////////////////////////////////////////////////// /* ? : C : C ( ) A B C D # define N 10. */ ///////////////////////////////////////////////////////////// /* : using namespace std; class A{ public: virtual void f() { cout << "A::f() "; } void f() const { cout << "A::f() const "; } }; class B : public A { public: void f() { cout << "B::f() "; } void f() const { cout << "B::f() const "; } }; void g(const A* a) { a->f(); } int main(int argc, char *argv[]) { A* p = new B(); p->f(); g(p); delete(p); return 0; } : B : B ( ) A B::f() B::f() const B B::f() A::f() const C A::f() B::f() const D A::f() A::f() const , , g(const A* a) void f() const; */ ///////////////////////////////////////////////////////////// /* ,() 。 : A : A ( ) A B C D B, , C, , , D, , , */ ///////////////////////////////////////////////////////////// /* final, finally, finalize ? : B : B ( ) A final, , B final, C finally finally 。 D Java finalize() final 、 。 final , final , final , , 。 */ ///////////////////////////////////////////////////////////// /* : fun , 1, 0。 , 。 afname , tfname 。 , 。 。 #include <stdlib.h> #include <stdlib.h> int fun(char *source, char *target) { FILE *fs, *ft; char ch; if ((fs = fopen(source, 1 ) == NULL) return 0; if ((ft = fopen(target, "w")) == NULL) return 0; printf("
The data in file :
"); ch = fgetc(fs); while (!feof( 2 )) { putchar(ch); fputc(ch, 3 ); ch = fgetc(fs); } fclose(fs); fclose(ft); printf("

"); return 1; } "r",fs,ft */ ///////////////////////////////////////////////////////////// /* In C++, which of the following keyword(s) can be used on both a variable and a function? : A C E : A C E ( ) A static B virtual C extern D inline E const static , extern , , extern 。 const */ ///////////////////////////////////////////////////////////// /* ? #include <string.h> #include <stdio.h> #include <stdlib.h> void getmemory(char*p) { p=(char *) malloc(100); strcpy(p,"hello world"); } int main( ) { char *str=NULL; getmemory(str); printf("%s
",str); free(str); return 0; } : B : B ( ) A 'hello world" B C " " D free(ptr) ptr NULL, ptr , 。 ( char*str=“aaaaa”) NULL , , 。 ,getmemory ,p str , “ p=(char*) malloc(100);” p ,“strcpy(p,"hello world");” , str ,getmemory p , getmemory str 。 ,str , NULL。 */ ///////////////////////////////////////////////////////////// /* C++ , : : C : C ( ) A , B new/delete , C D , , , 。 A, , KB。 B, , , 。 D, malloc()、calloc()、realloc() , alloca() , 。 free() , */ ///////////////////////////////////////////////////////////// /* #include<stdio.h> main(){ int b=10,a=-11; a%=b%=4; printf("%d %d
",a,B); } ? : B : B ( ) A1 2 B-1 2 C-1 -2 D1 -2 c++ java , ( 3 ) 。a%b=a-a/b*b; 。 */ ///////////////////////////////////////////////////////////// /* void func() { char b[2]={0}; strcpy(b,"aaaa"); } () : A A Debug ,Release B Debug ,Release C Debug ,Release D Debug ,Release Debug ASSERT , , Release ASSERT, 。 , , , , , 。 */ ///////////////////////////////////////////////////////////// /* C , : typedef struct list_t{ struct list_t *next; struct list_t *prev; char data[0]; }list_t; 32 ,sizeof(list_t) ? : B A 4byte B 8byte C 5byte D 9byte , */ ///////////////////////////////////////////////////////////// /* volatile ? : A B C : A B C ( ) A , , ; , B volatile , Cvolatile D const volatile const volatile. 。 volatile 。 const 。 Java , volatile . , , . volatile , . */ ///////////////////////////////////////////////////////////// /* 0 ASCII 48, : main() { char a=’1’,b=’2’; printf(“%c,”,b++); printf(“%d
”,b-a); } : : C A3,2 B50,2 C2,2 D2,50 */ ///////////////////////////////////////////////////////////// /* c++ , const int i, i ? : A : A ( ) A B C D const 。 , */ ///////////////////////////////////////////////////////////// /* #include <stdio.h> void fun ( char *p,int n ) { char b [6] = "abcde"; int i; for ( i = 0,p = b;i < n;i + + ) p [i] = b [i]; } main( ) { char a [6] = "ABCDE"; fun (a,5); printf ("%s
",a ) ; } ? : B : B ( ) A abcde B ABCDE C edcba D EDCBA , f , a b, a , ABCDE, B 。 : void fun (char *p,int n ) { char b [6] = "abcde"; int i; for (i = 0;i < n;i++){ p [i] = b [i]; } } abcde */ ///////////////////////////////////////////////////////////// /* enum string{ x1, x2, x3=10, x4, x5, } x; x ? : C A 5 B 12 C 0 D enum, x 0, enum, x 。 */ ///////////////////////////////////////////////////////////// /* , ? : A : A ( ) A B C , , D , , 。 */ ///////////////////////////////////////////////////////////// /* , () : A C D A public public B private private C protected protected D public private (public): ; , ( )。 (private): ; , 、 。 (protect): ; 、 , 、 */ ///////////////////////////////////////////////////////////// /* ? class A { public: A(){} }; void foo(){ throw new A; } : B A catch (A && x) B catch (A * x) C catch (A & x) D , B , , A C throw , , , terminate 。 */ ///////////////////////////////////////////////////////////// /* : struct A{ long a1; short a2; int a3; int *a4; }; 64 sizeof(struct A) ? : A A 24 B 28 C 16 D 18 Win64 :long 8 、short 2 、int 4 、int* 8 ,C++ , :8+(2+4+2( 2 ))+8 = 24 */ ///////////////////////////////////////////////////////////// /* : : C : C ( ) A B C D ->( )-> ->( )-> ->( )-> ->( )-> ->( )-> ->( )-> */ ////////////////////////////////////////////////////////////// /* C 1 ? : B C A main B return 7&1; C char *p="hello"; return p == "hello"; D */ ////////////////////////////////////////////////////// /* extern "C"{} ? : A B A C++ extern "C", C , C++ B C++ C C C C++ D */