初始化将指针整数

初始化将指针整数

本文介绍了初始化将指针整数,未作施放[默认启用]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习如何编程,我遇到这个错误是这样的:初始化将指针整数,未作施放[默认启用]
有什么问题?

  //这个方案对三个孩子与自己喜爱的超级英雄
#包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;
主要()
{
CHAR Kid1 [12];
// Kid1可容纳11个字符的名称
// KID2将7个字符(麦迪加空0)
CHAR KID2 [] =麦迪
// Kid3也是7个字符,但具体定义
焦炭Kid3 [7] =安德鲁
// Hero1将7个字符(加空0!)
焦炭Hero1 =蝙蝠侠;
// HERO2将有额外的空间,以防万一
炭HERO2 [34] =蜘蛛;
炭Hero3 [25];
Kid1 [0] =K; // Kid1被定义字符逐个字符
Kid1 [1] ='A'; //效率不高,但它的工作
Kid1 [2] ='T';
Kid1 [3] ='我';
Kid1 [4] ='E';
Kid1 [5] ='\\ 0'; //永远不要忘记空0所以C知道什么时候
//字符串结尾
的strcpy(Hero3,无敌浩克);
的printf(%S \\'最喜欢的英雄为%s \\ n,Kid1,Hero1);
的printf(%S \\'最喜欢的英雄为%s \\ n,KID2,HERO2);
的printf(%S \\'最喜欢的英雄为%s \\ n,Kid3,Hero3);
返回0;
}


解决方案

 字符Hero1 =蝙蝠侠;

 字符Hero1 [] =蝙蝠侠;

i just started to learn how to program and i encountered this error that goes like this: "initialization makes integer from pointer without a cast [enabled by default]"What is the problem?

 // This program pairs three kids with their favorite superhero
#include <stdio.h>
#include <string.h>
main()
{
char Kid1[12];
// Kid1 can hold an 11-character name
// Kid2 will be 7 characters (Maddie plus null 0)
char Kid2[] = "Maddie";
// Kid3 is also 7 characters, but specifically defined
char Kid3[7] = "Andrew";
// Hero1 will be 7 characters (adding null 0!)
char Hero1 = "Batman";
// Hero2 will have extra room just in case
char Hero2[34] = "Spiderman";
char Hero3[25];
Kid1[0] = 'K';  //Kid1 is being defined character-by-character
Kid1[1] = 'a';  //Not efficient, but it does work
Kid1[2] = 't';
Kid1[3] = 'i';
Kid1[4] = 'e';
Kid1[5] = '\0';  // Never forget the null 0 so C knows when the
// string ends
strcpy(Hero3, "The Incredible Hulk");


printf("%s\'s favorite hero is %s.\n", Kid1, Hero1);
printf("%s\'s favorite hero is %s.\n", Kid2, Hero2);
printf("%s\'s favorite hero is %s.\n", Kid3, Hero3);
return 0;
}
解决方案
char Hero1 = "Batman";

should be

char Hero1[] = "Batman";

这篇关于初始化将指针整数,未作施放[默认启用]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 08:04