[Solved] How to change the local variable without its reference

This approach is hacky and fragile, but that interviewer is asking for it. So here’s an example for why C and C++ are such fun languages: // Compiler would likely inline it anyway and that’s necessary, because otherwise // the return address would get pushed onto the stack as well. inline void func() { // … Read more

[Solved] Explain the output of the following C program?

The code under consideration is, when modernized and given some missing spaces: #include <stdio.h> int main(void) { int a = 1, b = 2, c = 3; printf(“%d\n”, a += (a += 3, 5, a)); return 0; } My initial reaction was “dup of Why are these constructs undefined behaviour”, even though that is primarily … Read more

[Solved] “Hello world” c# program appear for a split of a second with Visual Studio [closed]

You are probably running the application in debug, without something to prevent it to close as soon as the job gets done. Basically, your code executes, and the application shuts because there is nothing else left to do. Two solutions: do as Štěpán Šubík recommands : put a Console.ReadKey(); start the application without debugging (Ctrl+F5 … Read more

[Solved] std::remove_if GCC implementation isn’t efficient?

Looks to me as though you’re running remove_if on a range of 100 characters since size is 100, but the “homebrew” runs until you find the nul terminator (which is only 10 characters in). Dealing with that using the change in your comment below, on GCC with -O2 I still see a difference of about … Read more

[Solved] Regex for this string format

Seeing as you asked for a C# example, Case Insensitive can be selected as one of the RegexOptions. I assumed the 13 was also meant to be a 2 digit number. using System.Text.RegularExpressions; … Regex regX = new Regex( @”(\d{1,2}):(\d{1,2})-([a-z]{2})-(\d{3,5})”, RegexOptions.IgnoreCase ); if( regX.IsMatch( inputString ) ) { // Matched } … solved Regex for … Read more

[Solved] Opening a text file is passed as a command line parameter [closed]

A starting point. Then what you want to do with the contents of the file is up to you using System.IO; // <- required for File and StreamReader classes static void Main(string[] args) { if(args != null && args.Length > 0) { if(File.Exists(args[0])) { using(StreamReader sr = new StreamReader(args[0])) { string line = sr.ReadLine(); …….. … Read more

[Solved] C compilation errors [closed]

You may need to declare f as float, I am not getting any error in the following: #include <stdio.h> int main(void) { int i,n; float f = 1; printf(“Enter value of n:”); scanf(“%d”,&n); for(i=1;i<=n;i++) { if(i%3==0) f=f/i; else f=f*i; } printf(“%f\n”, f); return 0; } 4 solved C compilation errors [closed]

[Solved] Why does this c++ program not function correctly?

Step through your code in order and you’ll see the problem: int main () { int a; int b; string number1; string number2; number1 = a; number2 = b; int output; output = a + b; getline (cin, number1); getline (cin, number2); cout << output; } You define four variables, fiddle with two of them … Read more

[Solved] is setw() and “\t” the same thing? [closed]

They have almost nothing in common. std::setw(int n) set the width of the next element that goes into the stream. So if you have things like: std::cout << “Hi,” << std::setw(12) << “there!”; This would print: Hi, there! ^^^^^^ <- 6 empty spaces were made here to fill the width If you set the width … Read more

[Solved] How to solve Error : else without a previous if [closed]

Use braces if a if/else block has multiple lines: if (choice==1) { printf(“Enter value of radius (cm) : “); scanf(“%f”, &radius); volume = 4/3 * pi * pow(radius,3); printf(“Volume of a sphere is %.2f”, volume); } else if (choice==2) { printf(“Enter value of voltage (volts) : “); scanf(“%f”, &volts); printf(“Enter value of resistance (ohms) : … Read more

[Solved] Convert an unknown database file from a windows software into a MySqli Database

The linked file seems to be a renamed Firebird database with structure version ODS 11.2 which corresponds to Firebird 2.5.x line. For making a quick peep into the database you can use IBSurgeon First Aid — http://ib-aid.com IB Expert (the Database Explorer feature) — http://ibexpert.net Free mode of FirstAID would let you peep into the … Read more

[Solved] Simulate a dead lock on SQL server using single client and single session

This is currently possible. The following code deadlocks itself BEGIN TRAN CREATE TYPE dbo.OptionIDs AS TABLE( OptionID INT PRIMARY KEY ) EXEC (‘DECLARE @OptionIDs dbo.OptionIDs;’) ROLLBACK This is a long standing issue due to the use of internal system transactions when creating the instance of the TVP that can’t access the lock taken by the … Read more