我有一个函数,需要一个类型的参数float**,但我不知道如何声明和初始化这个变量.
任何人都可以给我任何建议吗?更好的是,它是什么类型的变量?我已经查了几天了,任何搜索结果都是空的.
谢谢
编辑
这是有问题的功能
- (OSStatus)getBuffersInner:(float**)buffers numberOfBuffers:(int)chnls samples:(int)samples
{
int i, j ;
UInt32 frames ;
// zero out requested buffers if client needs more channels than exist in the channel map
for ( i = numberOfMappedChannels; i < chnls; i++ ) memset( buffers[i], 0, samples*sizeof( float ) ) ;
// place buffer pointers into bufferList, following the channelMap
for ( i = 0; i < fileDescriptor.mChannelsPerFrame; i++ ) {
j = inverseChannelMap[i] ;
resampledBufferList.list.mBuffers[i].mData = ( …Run Code Online (Sandbox Code Playgroud) 我正在尝试向函数提供一个char指针,然后用函数填充它,以便调用函数可以使用它.因为它总是在调用函数中给我奇怪的东西,我写了一个关于我所做的简单表示:
#include <stdio.h>
#include <stdlib.h>
void bla(char *t)
{
t = (char*) malloc(5);
if (t != 0) {
t[0] = 'h';
printf("%c\n", t[0]);
}
}
int main(int argc, char **argv)
{
char b[10];
bla(b);
printf("%c\n", b[0]);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我不太确定C传递参数副本是否有事可做.我需要将指针传递给指针,还是有更好的解决方案?
编辑:
对不起的家伙,但我没有得到它.你能看一下这个例子:
#include <stdio.h>
#include <stdlib.h>
void blub(char **t)
{
printf("%d\n", *t);
*t = (char*) malloc(sizeof(char) * 5);
*t[0] = 'a';
*t[1] = 'b';
printf("%d\n", *t);
printf("%d\n", *t[0]);
printf("%d\n", *t[1]);
}
int main(int argc, char **argv)
{
char *a;
blub(&a); …Run Code Online (Sandbox Code Playgroud) 关于结构和指针,如何x->x->x使用点运算符编写此表达式?
使用箭头操作符:x->x->x我轻松访问第三个元素.使用点运算符:(*x).x如何使用点运算符访问第三个元素?
我知道箭头操作符是点运算符的快捷方式,所以应该可以使用点运算符到达第三个元素?我可以使用变量:
struct node *var
var = (*ptr).next
(*var).x = some value
Run Code Online (Sandbox Code Playgroud)
这真的让我很烦.一直在寻找教科书和互联网上的任何地方,无法找到答案.
我试图将字符串的某些部分复制到其他新字符串中,但是当我尝试将其打印并打印结果时,它会给我带来奇怪的输出.我真的希望有人可以提供帮助.我有一种感觉,它是缺少指针的东西..这是我的来源;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void getData(char code[], char ware[], char prod[], char qual[])
{
printf("Bar code: %s\n", code);
/* Copy warehouse name from barcode */
strncpy(ware, &code[0], 3);
ware[4] = "\0";
strncpy(prod, &code[3], 4);
prod[5] = "\0";
strncpy(qual, &code[7], 3);
qual[4] = "\0";
}
int main(){
/* allocate and initialize strings */
char barcode[] = "ATL1203S14";
char warehouse[4];
char product[5];
char qualifier[4];
getData(&barcode, &warehouse, &product, &qualifier);
/* print it */
printf("Warehouse: %s\nID: %s\nQualifier: %s", warehouse, product, qualifier); …Run Code Online (Sandbox Code Playgroud) 我有一个指向struct的指针数组,在处理完数组后,指针位于内存块的末尾.我想释放内存块,所以我需要转到第一个内存字节并再次循环遍历指针数组以释放数组中的每个元素.你会如何指回内存块的第一个字节?
我在我的数组中存储一些char指针时遇到了一些麻烦
该方法应该采用char*数组和int指针,该指针是数组的大小.然后我循环并要求用户输入名称.然后我要打印它们; 但似乎我的阵列中没有任何东西.
注意我不能使用数组表示法进行此赋值,我必须使用指针表示法来访问数组的元素.
void sort_name(char* name[], int* items)
{
//store the names
cout << "In function items is " << *items << endl;
for(int i=0; i<*items; i++)
{
string str;
cout << "Enter name #" << (i+1) << ": ";
getline(cin, str);
char* current = new char[str.size() + 1];
*(name + i) = current;
}
for(int i=0; i<*items; i++)
{
cout << *(name + i) << endl;
}
}
Run Code Online (Sandbox Code Playgroud) 我一般都知道了指针的逻辑,但对于我来说,有一点与下面的代码有关.
#include <iostream>
using namespace std;
int main ()
{
int first = 50,
second = 150;
int * p1, * p2;
p1 = &first; //p1 is assigned to the address of first
p2 = &second; //p2 is assigned to the address of second
*p1 = 100; //first's value is changed as 100 by assigning p1's value to 100
*p2 = *p1; //now p2's value should be 100
p1 = p2; //I think we want to change p1's adress as …Run Code Online (Sandbox Code Playgroud) 我试图理解指针的指针是如何工作的,我得出了这个例子,它编译得很好.但是,当它执行时,我得到一个分段错误.PS:我不想f1()回来char *.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int f1(char **str_);
int main(int argc, char **argv)
{
char *str = NULL;
f1(&str);
printf("str : %s\n", *str);
str = realloc(str, (size_t) 0);
assert(str == NULL);
return 0;
}
int f1(char **str_)
{
if ((*str_ = realloc(*str_, sizeof(char) * 12)) == NULL)
{
fprintf(stderr,"realloc() failed\n");
exit(3);
}
(*str_) = "hello there";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我试图通过以下方式使用获取UIColor的白色值(例如redColor):
UIColor *col = [UIColor redColor];
CGFloat *white;
if([col getWhite:white alpha:nil])
{
NSLog(@"worked");
}
else
{
NSLog(@"didn't");
}
Run Code Online (Sandbox Code Playgroud)
但这总是打印"没有",我不明白为什么.UIColor.h的定义是"如果接收器具有兼容的颜色空间,则填充任何非NULL参数并返回'YES'.否则,参数保持不变并返回'NO'." 所以我假设接收器是一个不兼容的色彩空间....但我不知道这意味着什么.有任何想法吗?
我看过这个 -
当程序终止时,将释放由malloc(例如)分配并且未使用free()函数释放的内存.并且它由opearting系统完成.那么什么时候有或没有垃圾收集器进入图片?
或者是并非所有操作系统都在程序终止时自动释放内存?