Some library functions in the C language are optimized at compile time.
As in GCC
LOG2 (1) is optimized to be constant
But log2 (20) evaluates values at run time
Fabs will be optimized into machine (assembler) Instructions Fabs
So even if you
#include #include #include void main(void) { struct date today; struct time now; getdate(&today); gettime(&now); textcolor(WHITE); textbackground(BLUE); do { clrscr(); gotoxy(25,10); printf("today's date is
The main function is the entry point of C program, which is indispensable and cannot be duplicated.
The main function should return an integer value to the operating system, and a return of 0 indicates a normal end.
The main function used earlier
Like printf, this multimodal function is borrowed from the macros in Stdarg.h.
va_list : 用于定义遍历参数列表的指针; va_start : 让指针指向第一个参数; va_arg : 获取下一个参数,并向后移动一个位置; va_end : 释放指针,完成遍历.
1. Integer sum:
This example implements a summation of a series of
C language can not be separated from functions, the use of functions is also very convenient, but the use of functions have a price;
Especially in the repeated call, the function will be repeatedly pressure stack, out of the stack and waste some
Review the definition of function and the declaration of function first:
//这是一个求和函数的定义: int add(int x, int y) { return(x + y); } //可以这样声明: int add(int x, int y); //也可以这样声明: int add(int, int);
Define a function pointer to declare a function
Non-pointer parameters (that is, pass-value parameters) are not modified to the original value, and const does not make sense to it.
Const is used only for pointers.
1. The first usage: const type * variable:
This usage restricts the values that
The array parameter belongs to the pointer parameter.
Pointer parameter immediate address parameter (or reference parameter), this is the only way to modify the value of a parameter in a function.
If you take an array as an argument, whether you
1. Recursion is: The function itself calls itself
This is one of the simplest recursion, but it will always execute and can be terminated with CTRL + C.
#include void prn(void) { printf("C++Builder 2009\n");
1. Local Variables:
A local variable is also called an automatic variable, which declares that at the beginning of a function, it lives on the stack, and its life ends with the function returning.
#include int main(void) {
A function in C can return any type other than an array (excluding array pointers).
Does not specify the return type, in the previous C language version is the default return int, now C99, C + + is not supported.
void means that no return value is
1. If the function is not declared, it should be defined before the call:
#include /* 定义求大值函数 */ int MAX(int x, int y) { if (x > y) return x; else return y; } /* 定义求小值函数 */ int MIN(int x, int y) { return x } int main(void) {
Custom type names are typically capitalized to indicate that this is a custom type.
1. Rename unsigned long to UINT:
#include int main(void) { typedef unsigned long UINT; UINT num = 1234567890; printf("%lu\n", num); getchar(); return
In a structure, the data type of each field is unique; Using unions, you can store different data types in one field.
Different data types share a piece of memory. Of course, its memory size should be based on the big.
The data in the joint,
C Language memory allocation is simple: malloc, calloc, realloc, free
malloc (number of bytes); Returns the first address of the memory segment, void.
Calloc (number, type size); The difference with malloc is that it initializes the memory to be
1. About the first address of the array:
#include int main (void){ Char Cs[2][3] = { {' A ', ' B ', ' C '}, {' D ', ' E ', ' F '} }; Char *P1,*P2,*P3,*P4; P1 = P2 = P3 = P4 =
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.