C Language Errors and solutions ~ ~ ~ Keep on updating, record the process of growth

Source: Internet
Author: User

1.error C2296: ' & ': illegal, left operand have type ' char [3] '
scanf ("%d" &x);
A comma is missing.
scanf ("%d", &x);

2.char Array, run crashes when no array length is defined

Workaround: Type char array remember to define a length

The 3.char array defines the length, but the assignment is not as long as it is assigned, and the console prints "Hot hot ..."
That is because you are not assigned to the end, the program will be the default assigned to CC H, printed out as a hot word
For example, you define the array is char a[10], and finally you input from the console character array is "Lisi", the "Lisi" length is 5, so the storage space behind the default is CCCCCCH, printed out is the hot word

4, how to define a variable-length char array
(1). Dynamic allocation Ah ~ Each time the allocation, each additional character, the dynamic allocation of a char character space to him
char * p = (char*) malloc (sizeof (char) * *) and so on
(2). No way to define "variable-length array"
Char Array[x];

The value of x must be specified in the definition (when allocating space) or the program can get the value of X.

The basic realization of variable-length arrays is
Request a piece of memory to hold x elements when the number of elements is greater than X, increase the x/n element space (you can use memory replication)
Array-to-length requirements are static. A global array allocates space in the data segment when the system is initialized, and if the array size is ambiguous, the data segment cannot allocate space for it because there is other data to allocate space in the data segment, and the local variable array also requires the array to specify the size when creating the function call stack, because the local variable allocates space at the bottom of the stack. If the array size is unknown, subsequent growth of the stack will not know where to start.

In general, for this need, it is temporary to apply for dynamic memory as needed.

5.fatal error c1010:unexpected end of file while looking for precompiled header directive
This error appears under vc6.0, generally without header files StdAfx.h
Add # include "StdAfx.h" to the CPP file before recompiling

6.d:\test2\test2.cpp: Error C2106: ' = ': Left operand must be l-value
;
Error C2106: ' = ': Left operand must is L-value
It says: ' = ' must be a variable on the left, not a constant or an expression
For example, the following are some of the same mistakes:
5=3;
(i+j) = 3;

7.strlen (CH), where ch is char * type
To the length of the character array, the sizeof (CH)

8. The difference between. h and No. h in the header file.
There are. h is the header file of the C language
No. h is a header file for C + +
Take <string> and <string.h> for example:
In C + +, this is done by:
#include <string>//note is <string>, not <string.h>, with. h is the header file in the C language

Using Std::string;

Using Std::wstring;

Or

using namespace Std;

In the C language is
#include <string.h>

C Language Errors and solutions ~ ~ ~ Keep on updating, record the process of growth

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.