根据我对'&'运算符的了解,它返回内存中操作数的基址.
让我们想象下面的场景(就像在我的机器上一样):
现在,如果我写这样的东西:
void main() {
int i = 5411;
int *ip = &i;
char *c = &i;
printf("%d",*ip);
printf("%c",*c);
}
Run Code Online (Sandbox Code Playgroud)
第一个printf()应该给我5411.谈到第二个printf(),i的基地址包含10101001(高阶8位= 1字节用于char类型指针).因此*c应该给我169,转换为%c时是无效字符.
但是编译器给了我'#'或其他一些有效的输出.为什么会这样?有什么投入?
编辑(取自作者对其中一个答案的评论):
那只是一个虚拟案例,因为我离开了实际的机器.
实际情况是i = 5411
我有一个现有的winform应用程序,它没有使用Program.cs.我想用通常的代码添加Program.cs
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Run Code Online (Sandbox Code Playgroud)
但我有错误信息
应用程序在当前上下文中不存在.
怎么解决这个?
我正在讨论Tkinter和Python.我有一个基本的gui,上面有几个按钮,一个按钮消失,做了一些需要花费一些时间的东西,这是可变的.问题是,当我按下这个按钮时,我的整个gui锁定/没有正确显示 - 我猜是因为它试图做这些需要花费一些时间并阻止gui的东西.
我已经研究过线程和队列,但我无法弄明白.我想我需要在一个线程上启动我的查找方法,然后在它们返回时对结果进行排队,并在返回时更新列表框?
我在Windows上,如果这对我使用线程的方式有所不同.
亲切的问候
大卫
基本代码如下.
class Search:
def __init__(self, master):
self.seeds = []
frame = Frame(master, width=700, height=500)
frame.pack_propagate(0)
frame.pack(expand=YES, fill=BOTH)
#
# Search results
#
l2 = Label(frame, text="results")
l2.pack(anchor=W)
self.resultfield = Listbox(frame, selectmode=BROWSE)
self.resultfield.grid(row=3, column=1, sticky=N+W+S+E, columnspan=3)
self.resultfield.pack(fill=BOTH)
frame1 = Frame(frame)
frame1.pack()
# Button to action the search
self.getSearchbut = Button(frame1, text="Do Search", command=self.getSearch)
self.getSearchbut.grid(row=1, column=2)
self.getSearchbut.pack()
def getSearch(self):
sa = SearchApi(self.seeds)
results = sa.lookup(self)
for result in results:
self.resultfield.insert(END, user)
def putCSV(self):
print "put …Run Code Online (Sandbox Code Playgroud) 我尝试编写我的第一个小部件应用程序,我遇到了问题.所以,我有2个箭头:切换到左边并切换到右边.对于他们两个我想使用单个服务,它根据箭头的方向更改我的主屏幕小部件的视图.为了区分箭头的方向,我将额外的数据添加到我使用的每个意图中.这是我的示例代码:
RemoteViews remoteViews =
new RemoteViews(context.getPackageName(),
R.layout.presentation_layout);
Intent updateServiceIntent1 = new Intent(context, UpdateService.class);
updateServiceIntent1.putExtra("com.mycompany.direction", 1);
PendingIntent updateServicePendingIntent1 =
PendingIntent.getService(context, 0, updateServiceIntent1,
PendingIntent.FLAG_UPDATE_CURRENT);
//Action when we touch left arrow
remoteViews.setOnClickPendingIntent(R.id.left,
updateServicePendingIntent1);
Intent updateServiceIntent2 = new Intent(context, UpdateService.class);
updateServiceIntent2.putExtra("com.mycompany.direction", 0);
PendingIntent updateServicePendingIntent2 =
PendingIntent.getService(context, 0, updateServiceIntent2,
PendingIntent.FLAG_UPDATE_CURRENT);
//Action when we touch right arrow
remoteViews.setOnClickPendingIntent(R.id.right,
updateServicePendingIntent2);
ComponentName thisWidget =
new ComponentName(context, HelperWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(thisWidget, remoteViews);
Run Code Online (Sandbox Code Playgroud)
在服务中我做下一个:
@Override
public void onStart(Intent intent, int startId) {
Log.i(TAG, "direction " + intent.getIntExtra("com.mycompany.direction", -1) …Run Code Online (Sandbox Code Playgroud) 我正在将drupal从localhost部署到实时服务器.但是我无法访问这些页面:
我有http:// localhost/site/admin,所以我应该有http://liverserver.com/site/admin,但它说链接不存在.
我将所有文件复制到实时服务器.
然后,我正确地制作了数据库的副本,并将settings.php更改为新的mysql服务器.
该网站显示,但我的所有页面(干净的网址)都无法访问,无法理解为什么.
我正在使用Octave分析一些图像。现在,我使用两个嵌套的for循环访问每个像素,但这确实很慢。
我的代码是这样的:
for i = 1:size(im,1)
for j = 1:size(im,2)
p = im(i,j,1:3);
if (classRGB(class, [p(1),p(2),p(3)]) > 0)
## Apply some function to that pixel here
endif
endfor
endfor
Run Code Online (Sandbox Code Playgroud)
没有八度中的循环,有没有办法做到这一点?
提前致谢。
老实说,这是一个任务问题,但我无法找到解决方案.请记住,我不是要求答案,只是一些指导.
问题:设计一个在O(n)时间(线性)运行的算法,该算法可以在2D网格上定位单个可疑房屋(点).如果消耗等于或大于其两个垂直和两个水平邻居的电力消耗是可疑的.注意:只想要一个可疑的房子被退回
解决方案:甚至不确定如何实现这样的解决方案.如果你检查n个房子,你也可以检查周围的四个邻居.4n/n ^ 2,简化为4/n.这意味着随着网格的扩展,它不太可能找到可疑的房子.
我尝试过: - 不同的数据结构(大多数是nlogn) - 折叠网格(再次nlogn)
提前致谢.
编辑:
我的错误,网格是(nxn)使房屋数量n ^ 2,抱歉混乱.
EDIT2:
这确实是个问题,也许我读错了?
警方正在寻找电力消耗特别大的房屋.为了简化问题,想象一下他们正在调查在n×n网格上布置的房屋.电网上的每个房屋都有一些耗电量e(i,j).如果房屋的电力消耗等于或大于其垂直和水平邻居的每一个,警察会认为该房屋是可疑的.设计一个在O(n)时间内运行并返回可疑房屋位置的算法.
我正在尝试添加一个视图作为按钮的子视图,就像这样(btn1是UIButton);
[self.btn1 addSubview:view1];
Run Code Online (Sandbox Code Playgroud)
添加后,按钮不会提供任何与触摸相关的事件,按钮工作正常,不添加此子视图.
有什么想法吗?
我有一个SQL Server表,具有以下结构:
CREATE TABLE [dbo].[Log](
[LogID] [bigint] IDENTITY(1,1) NOT NULL,
[A] [int] NOT NULL,
[B] [int] NOT NULL,
[C] [int] NOT NULL,
[D] [int] NOT NULL,
[E] [int] NOT NULL,
[Flag1] [bit] NOT NULL,
[Flag2] [bit] NOT NULL,
[Flag3] [bit] NOT NULL,
[Counter] [int] NOT NULL,
[Start] [datetime] NOT NULL,
[End] [datetime] NOT NULL)
Run Code Online (Sandbox Code Playgroud)
该表用于记录活动.列A- E表示外键,Flag1- Flag3表示某些日志状态,列Start和End标记活动的开始和结束.
平均而言,该表每30秒更新一次,更新可以进行约50次插入/更新.
用户可以从UI进行查询,并过滤任何给定列上的数据以及列和列类型的所有组合.
优化此表的数据检索的最佳方法是什么:
A,D,E],[ A, Start, End]等,并为它们创建索引