小编Vai*_*mar的帖子

使用指针交换两个变量时,为什么会出现意外结果?

这两个函数用于在使用函数执行选择排序时使用指针交换变量selectionSort(int *,int).但是在排序之后,数组的一些元素变为零.

void selectionSort(int *x,int len){
    int i,j,max;
    for(i=len-1;i>=0;i--){
        max = 0;
        for(j=1;j<=i;j++){
            if(x[j]>x[max]){
                max = j;
            }
        }
        swap(x+max,x+i);
    }
}

void swap(int *a,int *b){
    //This one works perfectly
    int temp;
    temp=*b;
    *b=*a;
    *a=temp;
}


void swap(int *a,int *b){
    //This one gives unexpected results
    *a=*a+*b;
    *b=*a-*b;
    *a=*a-*b;
}
Run Code Online (Sandbox Code Playgroud)

c pointers

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

如何在 PHP 中使用 array() 声明关联数组?

这是给 php 警告

<?php
$xml = simplexml_load_file("videos.xml") or die("Error: Object creation 
Failed");
$videos = array();

foreach( $xml->children() as $video){
   $a= $video->Serial;
   $b=$video->URI;
   $videos[$a] = $b;
}

header('Content-type: application/json');
echo json_encode($videos);
?>
Run Code Online (Sandbox Code Playgroud)

第 8 行中的非法偏移类型。如何修复?

php xml-parsing

-7
推荐指数
1
解决办法
8790
查看次数

标签 统计

c ×1

php ×1

pointers ×1

xml-parsing ×1