On the problem of C language pointer assignment _c language

Source: Internet
Author: User
Tags sleep

A code:

Copy Code code as follows:

#include <stdio.h>
#include <stdlib.h>
#define UCHAR unsigned char
#define UINT unsigned int

void display (Uchar *p);

Char h[4] = {' A ', ' B ', ' C ', ' n '};
Char e[4] = {' E ', ' F ', ' L ', ' n '};
Char l[4] = {' M ', ' N ', ' O ', ' I '};
Char o[4] = {' X ', ' Y ', ' Z ', ' n '};

int main (void)
{
int i;
char c;
UINT SET[5];

Set[0] = h;
SET[1] = e;
SET[2] = l;
SET[3] = l;
SET[4] = o;

while (1) {
for (i = 0; i < 5; ++i) {
Display (Set[i]);
printf ("\ n");
Sleep (1);

}

}
}

void display (Uchar *p)
{
while (*p!= ' ") {
printf ("%c", *p);
printf ("%c", * (p+1));
++p;
}
}


alerts are as follows:

TEST.C:21: Warning: Assigning pointers to integers with no type conversion
TEST.C:22: Warning: Assigning pointers to integers with no type conversion
TEST.C:23: Warning: Assigning pointers to integers with no type conversion
TEST.C:24: Warning: Assigning pointers to integers with no type conversion
TEST.C:25: Warning: Assigning pointers to integers with no type conversion
TEST.C:29: Warning: Assigning an integer to a pointer when parameter 1 (' Display ') is passed, without type conversion

21-25 of them are
Set[0] = h;
SET[1] = e;
SET[2] = l;
SET[3] = l;
SET[4] = o;
29 is
Display (Set[i])

It's just an alarm, and it's good to run under Linux. But since the warning, it is worth discussing.

To be Continued ~
In the interest of ...

If any of you know. Can you reply and tell me?

------------------------------------------------------------

On this question, I asked xiaoding in the bedroom. After his amendment, the procedure has not been reported as a warning.

Copy Code code as follows:

#include <stdio.h>
#include <stdlib.h>
#define UCHAR unsigned char
#define UINT unsigned int

void display (Uchar *p);

Char h[4] = {' A ', ' B ', ' C ', ' n '};
Char e[4] = {' E ', ' F ', ' L ', ' n '};
Char l[4] = {' M ', ' N ', ' O ', ' I '};
Char o[4] = {' X ', ' Y ', ' Z ', ' n '};

int main (void)
{
int i;
char c;
int set[5];

SET[0] = (int) h;
SET[1] = (int) e;
SET[2] = (int) l;
SET[3] = (int) l;
SET[4] = (int) o;

while (1) {
for (i = 0; i < 5; ++i) {
Display ((UCHAR *) set[i]);
printf ("\ n");
Sleep (1);

}

}
}

void display (Uchar *p)
{
while (*p!= ' ") {
printf ("%c", *p);
printf ("%c", * (p+1));
++p;
}
}


Cast to int in the first address assignment of the font array. In function invocation. Because the input is required in the child function as the pointer, so in the previous call, can not simply write set[i]. Instead of passing the pointer over. The coercion type conversion (UCHAR *) is to match (Uchar *p).
-------------------------------------------
the 2 points that should be noted are:
1. The pointer can only be transmitted to the address, can not be transmitted. Otherwise, you will be forced to type conversions.
2. When doing type conversion and assignment, you should pay attention to the type of assignment matching.

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.