Error couting an Integer

recently I took it upon myself to start working on the Project Euler challenges. I am on problem seven, and have encountered a strange error in my code. In my code, I have a variable called, count that counts the number of prime numbers found, but wh...
more »

2017-09-28 18:09 (2) Answers

Pointer points to uninitialized variable

In the following program, ptr points to uninitialized variable x. Before printing ptr, I have assigned 10 to ptr and print it. #include <stdio.h> int main() { int *ptr; int x; ptr = &x; *ptr = 10; printf(" x = %d\n...
more »

2017-09-11 07:09 (3) Answers

What does mean "int(i)=1;"?

I am new to C++, I see following syntax in c++ to initialize variable. int(i)=1; Then, I have compiled in G++ compiler and compiler did not give any error or warning. So, What does mean int(i)=1; in C and C++? Also, I have tested in C, I though...
more »

2017-08-26 07:08 (1) Answers

Initialize transposed numpy array

I want to use the Singular-Value-Decomposition of matrix A. If possible I would write: V, S, W.T = np.linalg.svd(A) But I can't initialise an array with its transposed. Now I have two questions: As far as I understand the python internals ther...
more »

2017-07-18 14:07 (1) Answers

Always initialize variables in C

Some programmers say that you should always declare all variables in a beginning of a sequence (function) first in C although it is not necessary anymore since C99. Is it also a good idea to initialize all variables at the beginning or is it a waste ...
more »

2017-07-11 18:07 (5) Answers

Multiple constructors: the Pythonic way?

I have a container class that holds data. When the container is created, there are different methods to pass data. Pass a file which contains the data Pass the data directly via arguments Don't pass data; just create an empty container In Java, I...
more »

2017-06-26 19:06 (7) Answers

c++ how to initialize const elements of an array

i need a way to initialize const elements of an array for the program i am currently working on. The problem is that i have to initialize these elements with a function, there is no way to do it like this: const int array[255] = {1, 1278632, 188, .....
more »

2017-06-06 00:06 (3) Answers

Initializing arrays in kotlin

I am making a haiku generator in kotlin but I am getting a weird 'variable firstLineArray must be initialized' on this block of code. import java.util.Random fun oneSyllableWords() : String{ val oneSyllableWordArray = arrayOf("Life", "Love", "O...
more »

2017-05-29 16:05 (3) Answers

C array initializing - some basics

I'v read in a book that when you have a string like this "blabla", it means there is a hidden char array, and this expression returns the address to the first element, and it's like a const array . This makes me confused about 2 scenarios : char ...
more »

2017-05-25 10:05 (4) Answers

Evaluation of a statement in C language

struct { int a[2], b; } arr[] = {[0].a = {1}, [1].a = {2}, [0].b = 1, [1].b = 2}; How to evaluate this line in C language? General declaration of struct is different from this statement. Also accessing of an element in C can be done like [0]....
more »

2017-04-15 08:04 (6) Answers

Why is this nested macro replacement failing?

I am trying to apply the X Macro concept, in order to have the possibility to initialize all struct members to a custom default (invalid) value. I write the following code: #define LIST_OF_STRUCT_MEMBERS_foo \ X(a) \ X(b) \ X(c) #define...
more »

2017-04-12 17:04 (2) Answers

C char array v C char* initialization

The following is accepted as valid c code by gcc version 6.3: char white[] = { 'a', 'b', 'c' }; char blue[] = "abc"; char *red = "abc"; However the following fails: char *green = { 'a', 'b', 'c' }; // gcc error I am sure there is a perfe...
more »

2017-03-20 15:03 (2) Answers

C - Unusual array initialization

I am working on some legacy C code that has this unusual array initialization: uint32_t defsMB40000[REG40000_SIZE] = { #include "modbusDefs40000.h" }; The header file is a list of comma separated numbers and comments. I have never seen this con...
more »

2017-02-15 21:02 (1) Answers