Beiligong C-language single-choice questions

Source: Internet
Author: User

1. In a function, you can assign a storage unit to a variable as long as it is described

Error: A variable such as auto and register is assigned a storage unit when the function that defines it is called

Auto: The default local variable storage, (this variable definition when the dynamic storage is allocated space), after use (such as function end), the system is recycled, the entire process is System management, all called automatic variables

Register: Register storage, (usually variables are stored in memory, used to be read into the CPU processing, but this is time-consuming), if a variable is used very frequently, such as loop control variable, you can use this keyword to put this variable into the internal CPU registers to improve the operation speed, however, Because the CPU registers are limited, (only automatic variables and parameters can be set to register variables, and there is a limit to the number)

Static: The local variable defined by this keyword is placed in a static store, even after the function call ends, its memory space is not reclaimed, and the original value is maintained, so that the next time the function is called, the access is still the same variable, the static variable is initialized only once in the compilation phase. Although the variable defined by static is not recycled, if it modifies a local variable, it can only be used to define its function, and other functions cannot use the

Global variables are stored in static storage and are divided into two types:

Internal global variable area, with static declaration, its scope is this CPP file, other files can not be used

External local variables, without any declared global variables, default to external global Variables 1. As used in this CPP, directly using n, such as cross-text use, need to use the extern int n declaration once, this declaration does not produce a new variable

Just stating that n is in the other CPP

2. Swap the values of variables x and y without parameters

Func (int *x, int *y)

{

*x=*x+*y;*y=*x-*y;

*x=*x-*y;

}

3. Implementing a copy of a string

Func (char *s1,char *s2)

{

while (*s1++=*s2++);

}

4

FGETC (): function returns the next character from the stream of (file *) stream, if the end of the file is reached or if an error occurs, EOF is returned
Rewind () Moves the file pointer to the beginning specified by stream (stream), while clearing and streaming related errors and EOF tags
Ftell: Returns the current position of Stream stream (long) If an error occurs-1
Fseek: Setting location data for the given stream, int fseek (FILE *stream,long offset,int origin) (defined in stdio.h)
such as fseek (fp,-10,1) Move the file pointer fp from the current position to the first direction of the file 10 characters

F1 the contents of the file (f root) on the screen first, and then copy it to the (F root directory) F2
#include <stdio.h>
#include <stdlib.h>
int main ()
{
FILE *FP1,*FP2;
if ((Fp1=fopen ("F:\\f1.txt", "r")) = = NULL)//must have new text present
{
printf ("Cannot open f1\n");
Exit (0);
}
if ((Fp2=fopen ("F:\\f2.txt", "w")) = = NULL)//text if none, create new text
{
printf ("Cannot open f2\n");
Exit (0);
}
while (!feof (FP1))
Putchar (Fgetc (FP1));
Rewind (FP1);
while (!feof (FP1))
FPUTC (Fgetc (FP1), FP2);
Fclose (FP1), fclose (FP2);
return 0;
}

5

#include <stdio.h>
void aaa () {printf ("Hi");}
void BBB () {printf ("Hello");}
void CCC () {printf ("Bye");}
int main ()
{
void (*p[3]) () = {&aaa,&bbb,&ccc};//pointer array references three functions
return 0;
}

Beiligong C-language single-choice questions

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.