[Solved] Strange problem with variable in C program [closed]

The array str, because it doesn’t have an explicit size, is sized to exactly store what it is initialized with. And because an empty string only contains 1 character, namely a terminating null byte, your array is 1 element in size. This means str isn’t large enough to hold any string that’s not an empty … Read more

[Solved] I wonder what is exact meaning of “return”

The i < 0 and i == 1 lines do not use the dictionary at all. For those early terms, the dictionary lookup would be slower than the calculation anyway. The if (memo.ContainsKey(i)) { return memo[i]; } line also does not set anything new in the dictionary. It reads from the dictionary, but does not … Read more

[Solved] the output is throwing large numbers [closed]

you are getting bigger numbers because on this line for(int i=0;i<n;i++){ cin>>arr[n]; } You are changing the value on arr[n] (that doesn’t exist because you array goes from 0 to n-1). Basically you are not changing any value inside the array so its using trash values that were stored on the memory. The fix to … Read more

[Solved] Serializing not-nested objects as nested

I’m going to take a crack at it here and assume that with the info you’ve given you need a class structure like this: class Book { [XmlAttribute(“bookAttribute”)] public string bookAttribute = “”; [XmlElement(“Shelf”)] List<Shelf> Shelves = new List<Shelf>(); } class Shelf { } Then when you create the programmatic relationship between a book and … Read more

[Solved] How to call user defined functions in C++?

As mentioned by πάνταῥεῖ in a comment, it seems that you’ve a few misconceptions regarding scope of variables, about parameters and about return values. Let’s see if we can’t dispel some of those. First of all, lets talk about scope. When we declare a variable inside a block delimited with { and }, the variable … Read more

[Solved] Recursive C function

Let’s construct our number that doesn’t have three consecutive ones from left to right. It necessarily starts with at most two 1s, so it starts with either no 1s, a single 1, or two 1s. In other words, our number starts with either 0, 10 or 110. In all of these cases, the only restriction … Read more

[Solved] How this C code works?

Beware that this code, as is, contains errors: bad cast, undefined behavior and platform dependent results… This is pointer arithmetic. w initially points to the content at the address of the first element of t (this is what w = (unsigned short *)&t means). Then, hereafter, you access this memory as containing successives shorts. At … Read more

[Solved] c# put a byte[] into an database and retrive later [closed]

Use BINARY or VARBINARY to store binary data. string query = “INSERT INTO dbo.MyTable(Content) VALUES(@Content)”; using(SqlConnection connection = new SqlConnection(/*yout connection string here*/)) using(SqlCommand command = new SqlCommand(query, connection)) { connection.Open(); SqlParameter param = command.Parameters.Add(“@Content”, SqlDbType.VarBinary); param.Value = YourByteArrayVariableHere; command.ExecuteNonQuery(); } You could retrieve it by using a SqlDataReader to get data and than cast … Read more