declaration

mixed declarations and codes

瘦欲@ 提交于 2019-12-19 05:46:15
问题 When I compile function with "gcc -o dene -Wall -ansi -pedantic-errors dene.c" ,gcc emits no error.(can you look a line which starts with char ....,in if loop,) static void remove_negation(char *s,char *s1) { char **cmainp=malloc(sizeof(char*)*1); int len=0;int d=0; int i=0; cmainp[0]=malloc(sizeof(char)*300); len=strlen(s); for(i=0;i<len;++i) { if(s[i]=='-') if(i==0 || s[i-1]==',') /*look*/ {char *p=malloc(sizeof(char)*3); /*look*/ ++i; p[0]=s[i]; p[1]='\0'; strcat(s1,","); strcat(s1,p);

Understanding two ways of declaring a C string [duplicate]

帅比萌擦擦* 提交于 2019-12-19 04:46:23
问题 This question already has answers here : How to declare strings in C [duplicate] (4 answers) Closed 4 years ago . A few weeks ago I started learning the programming language C. I have knowledge in web technologies like HMTL/CSS, Javscript, PHP, and basic server administration, but C is confusing me. To my understanding, the C language does not have a data type for strings, just characters, however I may be wrong. I have heard there are two ways of declaring a string. What is the difference

why change “complex*16” to “complex(16)” cause the runtime increased unreasonably in fortran?

此生再无相见时 提交于 2019-12-19 04:32:09
问题 This fortran code was originally written in Fortran 77 format(I will show it later). After I got it, I changed it into f90 free format via a converting tool. Using intel fortran compiler ifort , the compiation and running is just as fine as before. Then I want to do more, I want to transform nonstandard,obsolete data type declaration f77 style like: real*8 , complex*16 etc into f90 standard real(8) , complex(16) . But I found an unbelievable thing. I just changed one "complex*16" into

Variable declaration and definition

梦想的初衷 提交于 2019-12-19 04:15:14
问题 int x; Is this a declaration or a definition? As I write the following code, #include <stdio.h> int main(void) { int x; printf("%p",&x); return 0; } it prints some address. So as memory is allocated, int x; can't be just a declaration. So is it a definition? 回答1: From the C standard (n1256): 6.7 Declarations ... 5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition of an identifier is a declaration for that identifier that: — for an object, causes

What does it mean when there is a comma inside an array declaration? e.g. float[,]

ⅰ亾dé卋堺 提交于 2019-12-18 13:53:52
问题 I have some code I'm trying to understand while learning C#. I do not understand what I even need to search Google for to get here, but the code is as follows: float[,] heightAll = terData.GetHeights(0, 0, allWidth, allHeight); Why does the array declaration have a comma in between the brackets? 回答1: That would be a two-dimensional array. You can also specify more dimensions: Multidimensional Arrays (C# Programming Guide) 回答2: Each comma adds an additional dimension to the array [,] = 2

declaration of variables with same name as global,local and static

耗尽温柔 提交于 2019-12-18 13:38:27
问题 I have the following code snippet and I have to analyse what the output will be: #include <stdio.h> void f(int d); int a = 1, b = 2, c = 3, d = 4; int main(){ int a = 5, c = 6; f(a); f(b); f(c); printf("%d %d %d %d\n",a,b,c,d); return 0; } void f(int d){ static int a = 0; a = a + 7; b = a + d; c++; d--; printf("%d %d %d %d\n",a,b,c,d); } The output I've got is as follows: 7 12 4 4 15 26 5 11 21 27 6 5 5 27 6 4 This really baffled me. I noticed that in all 3 function calls the globally

Declaring an object before initializing it in c++

佐手、 提交于 2019-12-18 10:59:28
问题 Is it possible to declare a variable in c++ without instantiating it? I want to do something like this: Animal a; if( happyDay() ) a( "puppies" ); //constructor call else a( "toads" ); Basially, I just want to declare a outside of the conditional so it gets the right scope. Is there any way to do this without using pointers and allocating a on the heap? Maybe something clever with references? 回答1: You can't do this directly in C++ since the object is constructed when you define it with the

How do I pass a hash to a function in Perl?

前提是你 提交于 2019-12-18 10:48:10
问题 I have a function that takes a variable and an associative array, but I can't seem to get them to pass right. I think this has something to do with function declarations, however I can't figure out how they work in Perl. Is there a good reference for this and how do I accomplish what I need? I should add that it needs to be passed by reference. sub PrintAA { my $test = shift; my %aa = shift; print $test . "\n"; foreach (keys %aa) { print $_ . " : " . $aa{$_} . "\n"; $aa{$_} = $aa{$_} . "+"; }

What's the purpose of this [1] at the end of struct declaration?

余生长醉 提交于 2019-12-18 10:11:43
问题 I was snooping through my MSP430 microcontroller's header files, and I ran into this in <setjmp.h> : /* r3 does not have to be saved */ typedef struct { uint32_t __j_pc; /* return address */ uint32_t __j_sp; /* r1 stack pointer */ uint32_t __j_sr; /* r2 status register */ uint32_t __j_r4; uint32_t __j_r5; uint32_t __j_r6; uint32_t __j_r7; uint32_t __j_r8; uint32_t __j_r9; uint32_t __j_r10; uint32_t __j_r11; } jmp_buf[1]; /* size = 20 bytes */ I understand that it declares an anonymous struct

When do I define objective-c methods?

↘锁芯ラ 提交于 2019-12-18 10:01:45
问题 I'm learning Objective-C, and have a C/C++ background. In object-oriented C++, you always need to declare your method before you define (implement) it, even if it is declared in the parent class. In procedural-style C, IIRC, you can get away with just defining a function so long as it is only called from something else in the same compilational unit (ie. the same file) that came later on in the file (well, provided you don't declare it elsewhere with "extern"). Now, in Objective-C, it appears