当前位置:网站首页>C language practice questions + Answers:
C language practice questions + Answers:
2022-07-24 08:49:00 【aaawitch】
One
1. set up x The value of is 15,n The value of is 2, Expression x%=(n+=3) After operation ,x The value of is ( 0 ).
2. set up int a=7,b=9,t; After executing the expression t=(a>b)?a:b after ,t The value of is ( 9 ).
3. The output of the following program segment is ( 210 322 ).
int a=1234; a=a&0377; printf(“%d %o\n”,a,a);
4.a The array is defined as follows , In memory order ,a All elements in the array are ( a[0], a[1], a[2] ).
char a[3];
5. The following macro definitions are provided , Then execute the assignment statement a=PP*20;(a by int Type variable ) after ,a The value of is ( 8140 ).
#define PR 80
#define PP PR+403
6. stay C In the program , There are three ways to assign address values to pointer variables , They are :( )、( ) and ( ).
answer :int i, a[10], *p1, *p2;
(1)p1=&i; Assign a value to a pointer variable whose base type is an integer with the address of the integer variable
(2)p2=a; p2=a+3; Give the address to the pointer variable with the array name ;
(3) p1=p2; Assign values to pointer variables through pointer variables ;
7. stay C In file , The two code forms of data are ( ASCII file ) and ( Binary ).
8.C Call in language ( fopen() ) Function to open a file , call ( fclose() ) Function close file , call ( fseek() ) Function can realize random reading and writing of files .
9. If you have any int a[3]={10,12,30}; be a+1 yes ( &a[1] ) The address of ,*(a+2)=( 30 ).
Two
1. stay Turbo C in , Integer data occupies... In memory 2 Bytes .( v )
2. expression 1/4+2.75 The value of is 3.( x )
answer :1/4=0;0+2.75=2.75
1/4 In this expression 1 and 4 They are all literal integers Then the result is also an integer value 0
therefore The expression should be 2.75
3. There is only one type of structure .( x )
answer : Structure types can be customized and declared by users
4. If the function has no return value , Then it must be invisible .( x )
5.C Language can only deal with text files and binary files .( v )
3、 ... and choice question (20 branch )
1. set up int a=12; expression a+=a-=a*=a The value of is ( C ).
A 12 B 144 C 0 D 132
+=、-=、*= These three operators are executed from right to left
First step perform a=a*a a=144;
The second step perform a=a-a a=144-144=0;
The third step perform a=a+a a=0+0=0;
2. The output of the following program is ( C ).
int main( )
{
int a=011;
printf(“%d\n”,++a);
}
A 12 B 11 C 10 D 9
a=011 Express 8 Base number , yes 9,++a Means to add first 1, have to a=10, So the result is 10
3. The output of the following program is ( D ).
#define ADD(x) (x)+(x)
int main()
{
int a=4,b=6,c=7,d=ADD(a+b)*c;
printf(“d=%d”,d);
}
A d=70 B d=140 C d=280 D d=80
add(x) This is replaced by X+X
The formula finally becomes (a+b)+(a+b)*c
4. The correct assignment statement in the following options is (char a[5],*p=a;)( A ).
A p=“abcd”; B a=“abcd”; C *p=“abcd”; D *a=“abcd”;
p It's a character pointer , take “abcd” The address of p, That is to say p Point to “abcd" The first address , That is to say
Point to ‘a' The address of ;
B In the options ,a It's a pointer constant
C、D Variable on the left , On the right is the pointer
5. if k For shaping , be while Loop execution ( D ) Time .
k=2; while(k==0) printf(“%d”,k); k--; printf(“\n”);
A 10 B 9 C 0 D 1
while After the first cycle of , because (k==0) Not meeting the conditions ! So the cycle stops ,k The value of is also 2;
6. When the array name is passed to the formal parameter as an argument , The array name is processed as ( C ).
A The length of the array B The number of elements of the array C The first address of the array D The value of each element in the array
7. Two pointer variables cannot ( A ).
A. Add up B Compare C Subtracting the D Point to the same address
A. Add up , It's not that we can't , It's meaningless
B. Subtracting the , Yes. , For example, a pointer points to the beginning of the string , The end of another pointer , Subtract to get the number of strings
C. Compare , Yes. , We can compare whether they are equal , You can also compare who is big and who is small
D. Point to the same address , No need to explain , Certainly.
8. If there are the following program segments , Then the value is 6 The expression of ( D ).
struct st{ int n;struct st *next;};
static struct st a[3]={5,&a[1],7,&a[2],9,‘\0’},*p; p=&a[0];
A p++->n B p->n++ C (*p).n++ D ++p->n
#include<stdio.h>
void main(void)
{
structst { int n; structst* next; };
// Type of structure st, Two members : An integer member n, A pointer ( quote ) Type members next, This pointer is used to point to the structure type st The variable of
structst a[3] = { 5,&a[1],7,&a[2],9,&a[0] }, * p;
// Define an inclusion 3 Elemental st An array of struct types a, The three elements are {5,&a[1]},{7,&a[2]},{9,&a[3]}.
//( In each element , The first 1 Members correspond to n, The first 2 Members correspond to next) It also defines a point that can point to st Pointer to structure type variable p
p = &a[0];
//p Point to st Type array a Of the 1 Addresses of elements ( The first address )
// Then the value is 6 The expression of
//p ++ ->n //p->n Point to 5, Take the value first and increase it to 6++=6
//p->n ++ //p->n Point to 5, Take the value first and increase it to 6++=6
//(*p).n ++// ditto
//++ p->n // Point to p->n value 5++=6
printf("%d\n", ++p->n);
}
/*
expression A Equate to p->n then p=p+1, The expression value is p Before self increase p->n The value of 5
expression B First calculate p->n Value , Which is equivalent to a[0].n( The value is 5), And then execute (a[0].n)++, Note that it takes value first and then increases automatically , So the value of the expression is still 5
expression C First calculate (*p).n, That's equivalent to a[0].n( The value is 5), And then execute (a[0].n)++ Just like expression B The same , The value of the expression is still 5
expression D That's right. , amount to ++(a[0].n), The value is 6
*/
9. To open an existing non empty file "file" For modification , Choose the right statement ( C ).
A fp=fopen("file","r"); B fp=fopen("file","w");
C fp=fopen("file","r+"); D fp=fopen("file","w+");
r Open read-only file , The file must exist .
r+ Open a read-write file , The file must exist .
w Open write only , If the file exists, the file length is clear as 0, That is, the contents of the file will disappear . If the file does not exist, create it .
w+ Open a read-write file , If the file exists, the file length is clear to zero , That is, the contents of the file will disappear . If the file does not exist, create it .
a Open write only files in an additional way . If the file does not exist , The file will be created , If the file exists , The data written will be added to the end of the file , That is, the original contents of the document will be preserved .
a+ Open a read-write file as an attachment . If the file does not exist , The file will be created , If the file exists , The written data will be added to the end of the file , That is, the original contents of the document will be preserved .
3、 ... and 、 Write the running results of the following programs .
1.main( )
{ int a[6]={10,6,23,-90,0,3},i;
invert(a,0,5);
for(i=0;i<6;i++) printf(“%d,”,a[i]);
printf(“\n”);
}
invert(int *s,int i,int j)
{ int t;
if(i<j)
{ invert(s,i+1,j-1);
t=*(s+i);*(s+i)=*(s+j);*(s+j)=t;
}
}
Output results :3 0 -90 23 6 10

invert(int* s, int i, int j)/* Defined function invert, The parameter s It's the pointer type ,i,j Is an integer */
{ // Function entrance
int t; // Definition t Is an integer
if (i < j) // If i<j
{
invert(s, i + 1, j - 1); /* hold s,i+1,j-1 Call the function as an argument invert, This is the vector usage of a function */
t = *(s + i);
*(s + i) = *(s + j);
*(s + j) = t;
// These three lines are pointers (s+i) With the pointer (s+j) Point to the value exchange
} //if End of chunk
} // End of the function
// This function is used to drop the items in the array , That is, the last item becomes the first item , The first item becomes the last ……
main()
{
int a[6] = { 10,6,23,-90,0,3 }, i; // Define an array a And integer variables i
invert(a, 0, 5); // In array a The address of 、 Numbers 0、5 Call the function as an argument invert
for (i = 0; i < 6; i++) printf("%d", a[i]); // function invert Put the array a Of 6 Output after sorting items
printf("\n"); // Last output enter
}
Four 、 Read the following procedure , stay Fill in the appropriate content , Make the program complete .
seek 100~200 All prime numbers between .
(1)
main()
{ int m,k,i,n=0;
for(m=101;m<=200;m+=2)
{ if(n%10==0) printf("\n");
k=sqrt(m);
for(i= (2) ;i<=k;i++) if(m%i==0) (3) ;
if(i== (4) )
{ printf("%d ",m);n++;}
}
}
(1)#include<stdio.h> #include<math.h> (2)i=2 (3) break (4)k+1
#include<stdio.h>
#include<math.h>
int main()
{
int m, k, i, n = 0;
for (m = 101; m <= 200; m += 2)
{
if (n % 10 == 0)
printf("\n");
k = sqrt(m);
for (i = 2; i <= k; i++)
if (m % i == 0)
break;
if (i == k + 1)
{
printf("%d ", m);
n++;
}
}
}
边栏推荐
- Change of sheetname
- The solution of [an error occurred while trying to create a file in the destination directory: access denied] is prompted when installing the software
- Hack the box - File Inclusion module detailed Chinese tutorial
- Summary of points management system project
- Dao race track is booming. What are the advantages of m-dao?
- Sed add content after a line
- In the next bull market, can platofarm, the leading project in the Web3 world, set foot on the top of the mountain
- From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
- Cyclic multiple scatter
- Kotlin学习笔记1——变量、函数
猜你喜欢

【一起上水硕系列】June总结+no 焦虑+July计划+如何考试+如何提升

Learn the rxjs operator

4、 Midway integrates swagger and supports JWT bearers

Source code analysis of BlockingQueue (arraybq and linkedbq)

Developing ebpf program with go language

Wargames NATAS (0-10) problem solving essay

【FFH】OpenHarmony啃论文成长计划---cJSON在传统C/S模型下的应用

Okaleido tiger NFT is about to log in to binance NFT platform, and the era of NFT rights and interests is about to start

面试官:哥们Go语言的读写锁了解多少?

Scatter chart - date
随机推荐
【FFH】实时聊天室之WebSocket实战
3587. Connected graph (Jilin University postgraduate entrance examination machine test question)
[Shangshui Shuo series] final rad New Literacies
Summary of points management system project
安装软件时提示【An error occurred while trying to create a file in the destination directory: 拒绝访问】的解决方法
3、 Midway interface security certification
How to integrate and use log4net logging plug-in in vs2019 class library
After two days of tossing and turning, I finally wrote my first fluent app, which almost tortured me into a nervous breakdown
Kotlin learning note 1 - variables, functions
Recursive performance test
Php+spool to realize the shell client of web version
Precautions for using kettle excel input
In the next bull market, can platofarm, the leading project in the Web3 world, set foot on the top of the mountain
Houdini official HDA sidefx labs installation
Shell script backup mongodb database
Web3 traffic aggregation platform starfish OS interprets the "p2e" ecosystem of real business
Dao race track is booming. What are the advantages of m-dao?
Kotlin学习笔记1——变量、函数
C# 简述里氏替换原则的应用
Source code analysis of BlockingQueue (arraybq and linkedbq)