相关疑难解决方法(0)

如何在C中确定数组的大小?

如何在C中确定数组的大小?

也就是说,阵列可以容纳的元素数量是多少?

c memory arrays

907
推荐指数
17
解决办法
183万
查看次数

找到二维字符串数组中的字符串数

给定一个字符串数组,我需要找出其中的字符串数.

我跟着这个

但如果我将其传递给函数,这不起作用.

这是我试过的代码

#include<string>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int f1(char* input1[])
{

    string s="";

    cout<<sizeof(input1)<<endl; //print 4
    cout<<sizeof(char*)<<endl;  //print 4
    int l=sizeof(input1) / sizeof(char*);
    //giving l=1 here but should be 8
}

int main()
{
    char *str2[]={"baba","sf","dfvf","fbfebgergrg","afvdfvfv","we","kkhhff","L"};
    int l=sizeof(str2) / sizeof(char*);
    cout<<l<<endl; //print 8
    cout<<sizeof(str2)<<endl; //print 32
    cout<<sizeof(char*)<<endl; //print 4
    f1(str2);
}
Run Code Online (Sandbox Code Playgroud)

c++ arrays string

8
推荐指数
1
解决办法
244
查看次数

标签 统计

arrays ×2

c ×1

c++ ×1

memory ×1

string ×1