$(":input#single").trigger('change');
Это сработало для моего сценария. У меня есть 3 комбо & amp; связать с событием chainSelect, мне нужно передать 3 значения по URL & amp; по умолчанию выберите все выпадающее. Я использовал это
$('#machineMake').val('<?php echo [110] Это сработало для моего сценария. У меня есть 3 комбо & amp; связать с событием chainSelect, мне нужно передать 3 значения по URL & amp; по умолчанию выберите все выпадающее. Я использовал это
[111] И первое событие сработало.
GET['headMake']; ?>').trigger('change');
И первое событие сработало.
Ваш фрагмент кода правильный. Однако указатели и массивы в C действительно разные. Проще говоря, «указатель на тип T» не то же самое, что «массив типа T».
Пожалуйста, посмотрите C Faq , где обсуждаются указатели и массивы, чтобы лучше понять это.
arrays in C are represented and manipulated by a pointer to the first element, e.g.
int arr[50];
int * ptr1 = arr;
int * ptr2 = &arr[0];
in this example, ptr1 == ptr2 because the address of the first element of the array and the base pointer for the array are the same.
so your basic example is correct, though I suspect that the malloc should probably be:
int* reversed = malloc(sizeof(int)*len);
В педантичной теории массивы и указатели - разные вещи, поскольку массив определяет область памяти и, следовательно, размер массива является частью его типа. Итак, говорят, что имя массива распадается на указатель при использовании в этом контексте. Подробное объяснение приведено в C-FAQ .
На практике они такие же, поскольку формально a [i]
то же самое, что * (a + i)
, и поэтому серверная часть компилятора обрабатывает имя массива и указатель точно так же. Единственное отличие, о котором стоит беспокоиться, это то, что
void foo()
{
int a[5]; // allocates five words of space on the stack
int *b; // allocates *one* word of space on the stack (to hold the pointer)
}
Ваш фрагмент кода в порядке. Просто будьте осторожны, чтобы освободить память, которую выполняет ваша функция malloc ()
у того, кто ее вызывает.
From a low level perspective, an array is a continuous chunk of memory that's accessed by the address of the beginning of that chunk and the offset, so from that abstraction level, it is a pointer. However, from C language perspective, an array type is different from a pointer type. Basically an array can be assigned to a pointer value but it's not the same type.
For the purpose of your function, you are doing OK.
A link to C-FAQ: Arrays and Pointers has been given already, but there is also a thorough explanation in C for Smarties: Arrays and Pointers. You may want to read the "Analyzing Expressions" page first.
A couple of things about your example which should be corrected:
int
instead of the correct size_t
for storing object sizes.malloc()
.One way to "fix" this second problem is to let the caller decide where the output is stored (perhaps the caller does not want or need a freshly allocated array):
int *reverse(int *out, int *l, size_t len) {
size_t i, j;
for (i = 0, j = len - 1; i < len; ++i, --j) {
out[j] = l[i];
}
return out;
}