logo资料库

c语言选择题练习.docx

第1页 / 共45页
第2页 / 共45页
第3页 / 共45页
第4页 / 共45页
第5页 / 共45页
第6页 / 共45页
第7页 / 共45页
第8页 / 共45页
资料共45页,剩余部分请下载后查看
1. Data Types, Operators and Expressions
英文题库 C 目录 1. Data Types, Operators and Expressions ...................................................................................1 Variable Names – 1 .....................................................................................................................1 Data Types and Sizes – 1.............................................................................................................3 Constants – 1.............................................................................................................................. 5 Declarations – 1.......................................................................................................................... 8 Arithmetic Operators – 1..........................................................................................................11 Relational & Logical Operators – 1........................................................................................... 14 Type Conversions – 1................................................................................................................17 Increment and Decrement Operators – 1................................................................................ 20 Bitwise Operators – 1............................................................................................................... 23 Assigment Operators & Expressions – 1...................................................................................26 Conditional Expressions – 1......................................................................................................29 Precedence and Order of Evaluation – 1..................................................................................32 Precedence and Order of Evaluation – 2..................................................................................36 Precedence and Order of Evaluation – 3..................................................................................40 2. Control Flow Statements.........................................................................错误!未定义书签。 If-then-else Statements – 1......................................................................错误!未定义书签。 Switch Statements – 1..............................................................................错误!未定义书签。 For Loops – 1............................................................................................ 错误!未定义书签。 While Loops – 1........................................................................................ 错误!未定义书签。 Break and Continue – 1 ............................................................................错误!未定义书签。 Goto & Labels – 1..................................................................................... 错误!未定义书签。 3. Functions and Structure of a Program.....................................................错误!未定义书签。 Basics of Functions – 1............................................................................. 错误!未定义书签。 Functions Returning Non-integers – 1..................................................... 错误!未定义书签。 External Variables – 1...............................................................................错误!未定义书签。 Scope of a Variable – 1............................................................................. 错误!未定义书签。 Static Variables – 1................................................................................... 错误!未定义书签。 Register Variables – 1............................................................................... 错误!未定义书签。 Automatic Variables – 1 ........................................................................... 错误!未定义书签。 C-Preprocessor – 1 ................................................................................... 错误!未定义书签。 File Inclusion – 1.......................................................................................错误!未定义书签。 Macro Substitution – 1.............................................................................错误!未定义书签。 Conditional Inclusion – 1 ..........................................................................错误!未定义书签。 4. Pointers and Arrays.................................................................................错误!未定义书签。 Pointers and Addresses – 1...................................................................... 错误!未定义书签。 Pointers and Function Arguments – 1......................................................错误!未定义书签。 Pointers and Arrays – 1............................................................................ 错误!未定义书签。 Address Arithmetic – 1.............................................................................错误!未定义书签。 i
Character Pointers and Functions – 1 ...................................................... 错误!未定义书签。 Pointers to Pointers – 1............................................................................ 错误!未定义书签。 Multidimensional Arrays – 1.................................................................... 错误!未定义书签。 Initialization of Pointer Arrays – 1............................................................错误!未定义书签。 Pointers Vs. Multi-dimensional Arrays – 1 ...............................................错误!未定义书签。 Command Line Arguments – 1.................................................................错误!未定义书签。 Pointers to Functions – 1..........................................................................错误!未定义书签。 Complicated Declarations – 1.................................................................. 错误!未定义书签。 5. Structures, Unions and Bit-Fields ............................................................ 错误!未定义书签。 Basics of Structures – 1............................................................................ 错误!未定义书签。 Structures and Functions – 1................................................................... 错误!未定义书签。 Arrays of Structures – 1............................................................................错误!未定义书签。 Pointer to Structures – 1.......................................................................... 错误!未定义书签。 Self-Referential Structures – 1................................................................. 错误!未定义书签。 Table Lookup – 1.......................................................................................错误!未定义书签。 Typedefs – 1 ..............................................................................................错误!未定义书签。 Unions – 1.................................................................................................错误!未定义书签。 Bit-fields – 1..............................................................................................错误!未定义书签。 6. Input and Output.................................................................................... 错误!未定义书签。 Standard Input & Output – 1................................................................... 错误!未定义书签。 Formatted Output – 1.............................................................................. 错误!未定义书签。 Variable Length Argument – 1................................................................. 错误!未定义书签。 Formatted Input – 1................................................................................. 错误!未定义书签。 File Access – 1...........................................................................................错误!未定义书签。 Error Handling – 1.................................................................................... 错误!未定义书签。 Line Input & Output – 1........................................................................... 错误!未定义书签。 String Operations – 1............................................................................... 错误!未定义书签。 Character Class Testing & Conversions – 1.............................................. 错误!未定义书签。 Ungetc – 1.................................................................................................错误!未定义书签。 Storage Management – 1.........................................................................错误!未定义书签。 Mathematical Functions – 1.....................................................................错误!未定义书签。 Random Number Generation – 1.............................................................错误!未定义书签。 7. Floating Point & Sizeof Operator.............................................................错误!未定义书签。 Float Datatype – 1.................................................................................... 错误!未定义书签。 Sizeof – 1.................................................................................................. 错误!未定义书签。 ii
1. Data Types, Operators and Expressions Variable Names – 1 1. C99 standard guarantees uniqueness of ____ characters for internal names. a) 31 b) 63 c) 12 d) 14 2. C99 standard guarantess uniqueness of _____ characters for external names. a) 31 b) 6 c) 12 d) 14 3. Which of the following is not a valid variable name declaration? a) int __a3; b) int __3a; c) int __A3; d) None of the mentioned 4. Which of the following is not a valid variable name declaration? a) int _a3; b) int a_3; c) int 3_a; d) int _3a 5. Variable names beginning with underscore is not encouraged. Why? a) It is not standardized b) To avoid conflicts since assemblers and loaders use such names c) To avoid conflicts since library routines use such names d) To avoid conflicts with environment variables of an operating system 6. All keywords in C are in a) LowerCase letters b) UpperCase letters c) CamelCase letters d) None 7. Variable name resolving (number of significant characters for uniqueness of variable) depends on a) Compiler and linker implementations b) Assemblers and loaders implementations 1
c) C language d) None 8. Which of the following is not a valid C variable name? a) int number; b) float rate; c) int variable_count; d) int $main; 9. Which of the following is true for variable names in C? a) They can contain alphanumeric characters as well as special characters b) It is not an error to declare a variable to be one of the keywords(like goto, static) c) Variable names cannot start with a digit d) Variable can be of any length 2
Data Types and Sizes – 1 1. Comment on the output of this C code? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. #include int main() { int a[5] = {1, 2, 3, 4, 5}; int i; for (i = 0; i < 5; i++) if ((char)a[i] == '5') printf("%d\n", a[i]); else printf("FAILED\n"); } a) The compiler will flag an error b) Program will compile and print the output 5 c) Program will compile and print the ASCII value of 5 d) Program will compile and print FAIL for 5 times 2. The format identifier ‘%i’ is also used for _____ data type? a) char b) int c) float d) double 3. Which data type is most suitable for storing a number 65000 in a 32-bit system? a) signed short b) unsigned short c) long d) int 4. Which of the following is a User-defined data type? a) typedef int Boolean; b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays; c) struct {char name[10], int age}; d) all of the mentioned 5. What is the size of an int data type? a) 4 Bytes b) 8 Bytes c) Depends on the system/compiler d) Cannot be determined 3
6. What is the output of this C code? 1. 2. 3. 4. 5. 6. 7. 8. #include int main() { signed char chr; chr = 128; printf("%d\n", chr); return 0; } a) 128 b) -128 c) Depends on the compiler d) None of the mentioned 7. Comment on the output of this C code? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. #include int main() { char c; int i = 0; FILE *file; file = fopen("test.txt", "w+"); fprintf(file, "%c", 'a'); fprintf(file, "%c", -1); fprintf(file, "%c", 'b'); fclose(file); file = fopen("test.txt", "r"); while ((c = fgetc(file)) != -1) printf("%c", c); return 0; } a) a b) Infinite loop c) Depends on what fgetc returns d) Depends on the compiler 8. What is short int in C programming? a) Basic datatype of C b) Qualifier c) short is the qualifier and int is the basic datatype d) All of the mentioned 4
Constants – 1 1. What is the output of this C code? #include int main() { enum {ORANGE = 5, MANGO, BANANA = 4, PEACH}; printf("PEACH = %d\n", PEACH); } a) PEACH = 3 b) PEACH = 4 c) PEACH = 5 d) PEACH = 6 2. What is the output of this C code? #include int main() { printf("C programming %s", "Class by\n%s Sanfoundry", "WOW"); } a) C programming Class by WOW Sanfoundry b) C programming Class by\n%s Sanfoundry c) C programming Class by %s Sanfoundry d) Compilation error 3. For the following code snippet: char *str = “Sanfoundry.com\0″ “training classes”; The character pointer str holds reference to string: a) Sanfoundry.com b) Sanfoundry.com\0training classes c) Sanfoundry.comtraining classes d) Invalid declaration 4. What is the output of this C code? #include #define a 10 int main() { const int a = 5; printf("a = %d\n", a); } 5 1. 2. 3. 4. 5. 6. 1. 2. 3. 4. 5. 1. 2. 3. 4. 5. 6. 7.
a) a = 5 b) a = 10 c) Compilation error d) Runtime error 5. What is the output of this C code? #include int main() { int var = 010; printf("%d", var); } a) 2 b) 8 c) 9 d) 10 1. 2. 3. 4. 5. 6. 6. What is the output of this C code? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. #include enum birds {SPARROW, PEACOCK, PARROT}; enum animals {TIGER = 8, LION, RABBIT, ZEBRA}; int main() { enum birds m = TIGER; int k; k = m; printf("%d\n", k); return 0; } a) 0 b) Compile time error c) 1 d) 8 7. What is the output of this C code? 1. 2. 3. 4. 5. 6. 7. 8. 9. #include #define MAX 2 enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX}; int main() { enum bird b = PARROT; printf("%d\n", b); return 0; } 6
分享到:
收藏