Programming Articles - Page 2683 of 3366

How do you get assembler output from C/C++ source in gcc?

Aman Kumar
Updated on 30-Jun-2025 13:22:39

3K+ Views

In this article, we will see how to generate the assembler output from C or C++ code using GCC. What is GCC The GCC, which stands for GNU Compiler Collection, is a set of compilers and development tools available for various operating systems such as Linux, Windows, and a wide variety of other OSs (operating systems). It supports mostly C and C++, but also Objective-C, Ada, Go, Fortran, and D. The Free Software Foundation (FSF) created GCC and distributed it as totally free (as in libre) software. How to Get Assembler Output The GCC has a great feature that allows ... Read More

Order of evaluation in C++ function parameters

Aman Kumar
Updated on 04-Aug-2025 16:02:00

268 Views

In C++, when we pass multiple arguments to a function, a common question arises, in what order are these arguments evaluated? Is it from left to right, right to left, or does it depend on the compiler? In this article, we will learn how function parameter evaluation works in C++, why the order of evaluation is important, and how it can vary across different compilers. Is the Order of Evaluation Defined in C++? The C++ standard does not guarantee a fixed order of evaluation for function arguments. This means compilers are free to evaluate arguments from left to ... Read More

Java Program to create Stream from a String/Byte Array

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

599 Views

Create an input stream and set the string:DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream("pqrs tu v wxy z".getBytes()));The getBytes() method is used to convert a string into sequence of bytes and returns an array of bytes.Now return one single input byte:(char) inputStream.readByte()Exampleimport java.io.ByteArrayInputStream; import java.io.DataInputStream; public class Demo { public static void main(String[] args) throws Exception {    DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream("pqrs tu v wxy z".getBytes()));       System.out.print((char) inputStream.readByte());       System.out.print((char) inputStream.readByte());       inputStream.close();    } }OutputPq

How to sort an array with customized Comparator in Java?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

2K+ Views

Let’s say the following is our string array and we need to sort it:String[] str = { "Tom", "Jack", "Harry", "Zen", "Tim", "David" };Within the sort() method, create a customized comparator to sort the above string. Here, two strings are compared with each other and the process goes on:Arrays.sort(str, new Comparator < String > () {    public int compare(String one, String two) {       int val = two.length() - one.length();       if (val == 0)       val = one.compareToIgnoreCase(two);       return val;    } });Exampleimport java.util.Arrays; import java.util.Comparator; public class Demo ... Read More

Java Program to get duration between two time instants

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

309 Views

Create two time instants:Instant time1 = Instant.now(); Instant time2 = Instant.now().plusSeconds(50);Use between() to get the duration between two time instants:long resMilli = Duration.between(time1, time2).toMillis();Exampleimport java.time.Duration; import java.time.Instant; public class Demo {    public static void main(String[] args) {       Instant time1 = Instant.now();       Instant time2 = Instant.now().plusSeconds(50);       long resMilli = Duration.between(time1, time2).toMillis();       System.out.println("Duration between two time intervals = "+resMilli);    } }OutputDuration between two time intervals = 50000

Java Program to create LocalDateTime from Clock

Nancy Den
Updated on 30-Jul-2019 22:30:25

492 Views

At first, set the Clock:Clock clock = Clock.systemUTC();Now, create LocalDateTime:LocalDateTime dateTime = LocalDateTime.now(clock);Exampleimport java.time.Clock; import java.time.LocalDateTime; public class Demo {    public static void main(String[] args) {       Clock clock = Clock.systemUTC();       System.out.println("Clock = "+Clock.systemDefaultZone());       LocalDateTime dateTime = LocalDateTime.now(clock);       System.out.println("LocalDateTime = "+dateTime);    } }OutputClock = SystemClock[Asia/Calcutta] LocalDateTime = 2019-04-19T09:29:50.605820900

Java Program to format LocalTimeDate as BASIC_ISO_DATE format

Nancy Den
Updated on 30-Jul-2019 22:30:25

511 Views

At first, set the date:LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 6, 20, 10);Now, format the datetime as BASIC_ISO_DATE format:String str = dateTime.format(DateTimeFormatter.BASIC_ISO_DATE);Exampleimport java.time.LocalDateTime; import java.time.Month; import java.time.format.DateTimeFormatter; public class Demo {    public static void main(String[] args) {       LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 6, 20, 10);       System.out.println("DateTime = "+dateTime);       String str = dateTime.format(DateTimeFormatter.BASIC_ISO_DATE);       System.out.println("Formatted date = "+str);    } }OutputDateTime = 2019-09-06T20:10 Formatted date = 20190906

Java Program to format LocalDateTime as ISO_WEEK_DATE format

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

186 Views

At first, set the date:LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 9, 10, 20);Now, format the datetime as ISO_WEEK_DATE format:String str = dateTime.format(DateTimeFormatter.ISO_WEEK_DATE);Exampleimport java.time.LocalDateTime; import java.time.Month; import java.time.format.DateTimeFormatter; public class Demo {    public static void main(String[] args) {       LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 9, 10, 20);       System.out.println("DateTime = "+dateTime);       String str = dateTime.format(DateTimeFormatter.ISO_WEEK_DATE);       System.out.println("Formatted date = "+str);    } }OutputDateTime = 2019-09-09T10:20 Formatted date = 2019-W37-1

How to format Java LocalDateTime as ISO_DATE_TIME format

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

4K+ Views

At first, set the date:LocalDateTime dateTime = LocalDateTime.of(2019, Month.JULY, 9, 10, 20);Now, format the datetime as ISO_DATE_TIME format:String str = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);Exampleimport java.time.LocalDateTime; import java.time.Month; import java.time.format.DateTimeFormatter; public class Demo {    public static void main(String[] args) {       LocalDateTime dateTime = LocalDateTime.of(2019, Month.JULY, 9, 10, 20);       System.out.println("DateTime = "+dateTime);       String str = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);       System.out.println("Formatted date = "+str);    } }OutputDateTime = 2019-07-09T10:20 Formatted date = 2019-07-09T10:20:00

Java Program to format date as Apr 14 2019 01:35 PM IST

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

123 Views

To format and display datetime, you need to use DateTimeFormatter and use the pattern as:DateTimeFormatter dtFormat = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a z");Above, the z is the timezone:MMM dd yyyy hh:mm a zNow, use the following for zone:ZonedDateTime dateTime = ZonedDateTime.now();Exampleimport java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; public class Demo {    public static void main(String[] argv) {       DateTimeFormatter dtFormat = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a z");       ZonedDateTime dateTime = ZonedDateTime.now();       String res = dateTime.format(dtFormat);       System.out.printf("Date = %s %n", res);    } }OutputDate = Apr 14 2019 01:35 PM IST

Advertisements