English 中文(简体)
正确的声明形式
原标题:correct form of declaration
  • 时间:2010-08-01 11:27:50
  •  标签:
  • c

这部法典的正确形式是什么?

<守则>char *x = malloc(100);

守则

<守则>#include <stdlib.h>
#include <stdio.h>
int main(){
    char *x=malloc(100);
    free(x);
    //in c++
    // char *x=new char[100];






     return 0;
}

这里的错误

<守则>1>------ Build started: Project: memory_leaks, Configuration: Debug Win32 ------
1>Build started 8/1/2010 2:32:21 PM.
1>PrepareForBuild:
1>  Creating directory "c:usersdaviddocumentsvisual studio 2010Projectsmemory_leaksDebug".
1>InitializeBuildStatus:
1>  Creating "Debugmemory_leaks.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  memory_leaks.cpp
1>c:usersdaviddocumentsvisual studio 2010projectsmemory_leaksmemory_leaksmemory_leaks.cpp(5): error C2440:  initializing  : cannot convert from  void *  to  char * 
1>          Conversion from  void*  to pointer to non- void  requires an explicit cast
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.64
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
最佳回答

你有有效的C码,但你试图与C++汇编者一道汇编。 (事实上,如果您将来源重新命名为memory_leaks.c,则您的发展环境可能自动援引C汇编者;memory_leaks.cpp。 它援引C++汇编者。

C和C++是不同的语言。 C++ 如同C一样,有额外的足迹,因为它从C类语言中演进,有额外的 st子。 但它现在使用自己的语言。 捐款。

尤其是,如果在<条码>上添加一个插物,那么你可以拿到汇编的C++代码,但获得的C++代码良好。 捐款:如果你在C++中重新编制方案,使用<代码>新<>/代码”;如果在C重新编制方案,则使用C汇编器。

问题回答

暂无回答




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签