哪个是在C++中声明指针的更好的约定?
MyClass* ptr
Run Code Online (Sandbox Code Playgroud)
(要么)
MyClass *ptr
我发现第一个有意义,因为我想声明MyClass指针而不是MyClass并指定一个类型修饰符.但我看到很多书推荐以后的会议.你能否遵循你所遵循的惯例的理性?
我试图在我的头文件中声明一个返回2D数组的函数.考虑到我们已经知道阵列的大小,怎么能实现呢?以下是我目前正在做的事情.
class Sample
{
public:
char[x][y] getArr();
void blah(int x, int y);
private:
const static int x = 8;
const static int y = 2;
char arr[x][y];
};
Run Code Online (Sandbox Code Playgroud) 对于家庭作业,当主类在同一行上实例化同一类的两个对象时,我很难理解行为,如下所示.请注意,赋值的对象是类的行为类似于int:
main () {
MyClass x,y = 5;
cout << "x = " << x << endl; // outputs x = 0...why not 5???
cout << "y = " << y << endl; // outputs y = 5
}
Run Code Online (Sandbox Code Playgroud)
这里是头文件类定义:
class MyClass {
public:
MyClass(int initValue = 0); //constructor
operator int() {return myValue}; //conversion operator to int
private:
int myValue;
}
Run Code Online (Sandbox Code Playgroud)
最后,我的源文件:
#include "MyClass.h"
MyClass::MyClass(int initValue) {
myValue = initValue;
}
Run Code Online (Sandbox Code Playgroud)
为什么不像y那样用x值初始化x?
以下声明在C中意味着什么?
char a = (10,23,21);
Run Code Online (Sandbox Code Playgroud)
使用"%u"打印"a"的值时,输出为21.
gcc并未给出任何错误.什么是这种声明以及它的用途是什么?
1:名称varchar2(30):='uu'|| '&(emp name)';
2:名称varchar2(30):='uu'|| '&emp name';
我不知道差异()是什么.
在第一种情况下,name = uu&(emo名称和
第二种情况,它促使用户输入值.
请任何机构解释我这背后的概念.
我是java编程的新手,我无法找到解决问题的方法.我认为这是一个非常容易的问题,但我无法弄清楚我做错了什么,所以我希望你们中的一个可以帮助我.问题是当我尝试在数组中存储一些数据时,它返回以下错误:
Exception in thread "main" java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
public class FetchData{
private String rows[][];
private int rowCount;
public FetchData(){
rowCount = 0;
}
public boolean ConnectAndFetch(String start, String end){
//not relevant to the problem
for(...){
List<WebElementdivList = driver.findElements(By.tagName("div"));
int divCount = 0;
int colCount = 0;
for (WebElement elem : divList) {
if(divCount 24){
if(colCount < 17){
System.out.println(elem.getText());
//System.out.println(colCount);
//System.out.println(rowCount);
rows[rowCount][colCount] = elem.getText();
colCount++;
} else {
rowCount += 1;
colCount = 0;
}
}
divCount++;
}
}
return true;
} …Run Code Online (Sandbox Code Playgroud) 我不确定如何提出这个问题所以我将从一些示例代码开始:
//header file
class A
{
public:
A();
private:
int x;
std::string arr[x];
}
//cpp file
class A
{
public:
A()
{
/*code to get the value of x from a cmd call*/
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码有效吗?更具体地说,我可以将我的头文件中的字符串数组大小为x,即使在创建A对象之前x没有特别赋值吗?
如果这不起作用,我唯一的另一种选择是使用动态分配的数组吗?
是否可以将数组发送到C函数而不先声明/定义它?
这可以用整数来实现.
int add(int a, int b) {
return (a + b);
}
void main(void) {
int c;
int a=1, b=2;
/* With declaring (works fine)*/
c = add(a, b);
/* Without declaring (works fine)*/
c = add(1, 2);
}
Run Code Online (Sandbox Code Playgroud)
对阵列有什么一点吗?
#include <stdio.h>
void print_int_array(int *array, int len) {
int i;
for (i = 0; i < len; i++)
printf("%d -> %d\n", i, *array++);
}
void main(void) {
int array[] = {1, 1, 2, 3, 5};
/* With declaring (works …Run Code Online (Sandbox Code Playgroud) 几个星期前,我开始学习编程语言C.我对网络技术有所了解,如HMTL/CSS,Javscript,PHP和基本服务器管理,但C让我感到困惑.据我所知,C语言没有字符串的数据类型,只有字符,但是我可能错了.
我听说有两种声明字符串的方法.声明字符串的这两行之间有什么区别:
a.)char stringName[];
b.)char *stringName;
我得到的char stringName[];是一个字符数组.但是,第二行让我感到困惑.据我所知,第二行是一个指针变量.是不是指针变量应该是另一个变量的内存地址?
我有以下简单的代码:
结构的第一次使用,f工作正常,但我不能malloc n- 我得到一个错误,它无法*无法分配给myValues*.我知道我不应该施放malloc,所以我该怎么做呢?怎么了?
确切的错误:
a value of type "void *" cannot be assigned to an entity of time "myValues *"
#include <stdio.h>
#include <stdlib.h>
typedef struct values
{
int a;
char c;
void *pv;
values *next;
} myValues;
int main(){
myValues f;
myValues *n = malloc(sizeof(myValues));
}
Run Code Online (Sandbox Code Playgroud)