您好我已经写了以下代码Turbo c++ compiler并尝试打印postfix和中缀,但它正在显示NULL pointer assignment.我不知道为什么会发生这种情况.请帮我....
提前致谢.
#include<iostream.h>
#include<stdio.h>
void main()
{
char *infix,*postfix;
cout<<"Enter postfix exp:";
gets(postfix);
cout<<"Enter infix exp: ";
gets(infix);
cout<<endl<<endl;
puts(postfix);
puts(infix);
}
Run Code Online (Sandbox Code Playgroud) 我有这个表达
(*p % 3 != 0) ? *p = (*p) + 1 : *p = (*p) + 2;
Run Code Online (Sandbox Code Playgroud)
在Turbo C++中,如果*p为11,则计算结果为14;如果*p为33,则计算结果为35
在GCC(Windows)中,它分别评估为12和35,这是预期的
括号为以下格式时,它工作正常:
(*p % 3 != 0) ? (*p = (*p) + 1) : (*p = (*p) + 2);
Run Code Online (Sandbox Code Playgroud)
这种差异有什么解释吗?我猜它归结为编译器使用的优先顺序的差异,但无法确定根本原因
我正在解决老师给我的一个问题并且遇到了一些问题.我应该给出以下代码的输出:(用Turbo C++编写)
#include<iostream.h>
void main()
{
char *p = "School";
char c;
c=++(*(p++));
cout<<c<<","<<p<<endl;
cout<<p<<","<<++(*(p--))<<","<<++(*(p++))<<endl;
}
Run Code Online (Sandbox Code Playgroud)
程序给出的输出是:
T,chool
ijool,j,i
Run Code Online (Sandbox Code Playgroud)
我得到了指针本身增量的部分,然后递增指针指向的值.但我没有得到字符串打印出来的部分ijool
有人可以帮我吗?
#include<stdio.h>
int main(){
char *ptr="Helio";
ptr++;
printf("%s\n",ptr);
//*ptr++;
printf("%c\n",++*ptr);/*Segmentation fault on GCC*/
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Q1)这在Turbo C++中运行良好,但在GCC上它会产生分段错误.我没有得到确切的理由.
可能是运营商优先是其中一个原因.
Q2)每个编译器都有不同的运算符优先级吗?
以下是我的代码.此代码在屏幕上移动文本.我正在做一个在学校提交的项目.遗憾的是,我们的项目必须使用Turbo C++而不是Visual Studio或CodeBlocks.
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
int main()
{
for(int fp=0, sp=getmaxx();fp <= (getmaxx()/4)-20, sp >= (getmaxx()/2)+60; fp++, sp--)
{
cleardevice();
setfillstyle(SOLID_FILL,RED);
bar(320,50,340,170);
bar(270,100,390,120);
settextstyle(SCRIPT_FONT,HORIZ_DIR,5);
outtextxy(fp-125,300,"Welcome To ");
outtextxy(sp,300,"MedStore");
delay(10);
}
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器显示错误
代码没有效果
有人可以指导我解决这个错误吗?
我要进行汇编测试,并且对汇编指针有疑问。我正在尝试锻炼,但无法解决。
考虑一下C中的语句:
int x=100, y=200;
int far *ptx;
int far *pty;
Run Code Online (Sandbox Code Playgroud)
假设指令已经执行:
ptx=&x;
pty=(int *)malloc(sizeof(int));
Run Code Online (Sandbox Code Playgroud)
我的问题是关于如何在汇编中编码以下几点:
ptx=pty*ptx=*pty我是C++编程的学生我正在尝试用c ++创建一个年龄计算器,但我坚持将变量与另一个变量相乘这里是代码:
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int birthmonth,birthyear,birthdate;
int currentmonth,currentyear,currentdate;
int year,month,weeks,cal,calx,days,hours;
cout<<"Hassan's Age Calculator\n\n";
cout<<"Enter Your Birth Year(i.e:1996):";
cin>>birthyear;
cout<<"\nEnter Your Birth Month(i.e:10):";
cin>>birthmonth;
cout<<"\nEnter date of Birth(i.e:27):";
cin>>birthdate;
cout<<"\nEnter The Current Month(i.e:7):";
cin>>currentmonth;
cout<<"\nEnter The Current Year(i.e:2013):";
cin>>currentyear;
cout<<"\nEnter Current Date(i.e:24):";
cin>>currentdate;
year=currentyear-birthyear;
month=year*12;
weeks=month*4.34;
cal=(year*365.242)+currentdate;
calx=cal+30.43;
days=calx-birthdate;
hours=days*24;
cout<<"\n\n\t\tYour Age is "<<year<< " in Years" ;
cout<<"\n\n\t\tYour Age is "<<month<< " in Months" ;
cout<<"\n\n\t\tYour Age is "<<weeks<<" in weeks";
cout<<"\n\n\t\tYour Age is …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Turbo-C++ 同时获得鼠标和键盘输入。
我想使用两个函数。第一个函数是main可以接受键盘输入或调用该delay函数dos.h以暂时停止main().
第二个函数处理鼠标输入:
void mouse()
{
union REGS in,out;
in.x.ax=1; // Show mouse pointer
int86(0x33,&in,&out); //interrupt call
while(1)
{
//print the location whenever it changes (not required)
}
}
Run Code Online (Sandbox Code Playgroud) class anurag
{
private:
int rollno;
char name[50];
int marks;
float percen;
void percentage(int num)
{
percen=(num/500)*100;
}
public:
void getdata(void)
{
cout<<"\n\nEnter the name of the student:";
gets(name);
cout<<"\n\nEnter the roll no: and the marks:";
cin>>rollno>>marks;
percentage(marks);
}
void display(void)
{
cout<<"\n\nThe name of the student is:";
cout.write(name,50);
cout<<"\n\nThe roll no: of the student is:";
cout<<rollno;
cout<<"\n\n The marks obtained is:"<<marks;
cout<<"\n\nThe percentage is:"<<percen;
}};
void main()
{
clrscr();
anurag F;
F.getdata();
F.display();
getch();
}
Run Code Online (Sandbox Code Playgroud)
为什么以下代码没有提供所需的输出?
完整的代码是正确的,但我在第28行只得到了这一个错误:declaration terminated incorrectly.
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<iostream.h>
class Rail
{
private:
char GetYN();
struct Train
{
int tno, nop;
char tname[50];
char dest[50];
float dist, fare;
}t;
public:
void Input();
void CreateFile();
void Display();
void Search();
void Modify();
void Delete();
void AddRecord();
}R;
void introduction();
{ \\This is where the error is (error: declaration terminated incorrectly)
clrscr()
cout << "\n\n";
cout << "\t =============================================================\n";
cout << "\t ** **\n";
cout << "\t ** WELCOME TO **\n"; …Run Code Online (Sandbox Code Playgroud)